1

During a conversation about coding vs natural language, it came to me that verbs in language are adjusted to match the tense. Specifically I was thinking about Spanish and how a singular verb "var" (go) is adjusted on the fly to match how it's used:

  • Voy - I go
  • Vas - you go
  • Va - he goes
  • Vamos - we go
  • Vais - you all go
  • Van - they go

So do any programming languages take this approach? can I declare a variable agnostically and then assign how it should be used? e.g.

const test; 
console.log(testString) 
console.log(testInt)
console.log(testFloat) 
console.log(testBool)

Honestly I can't think of a use case unless you were developing something for end users/learning to program, but an interesting idea imo.

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

0

While I'm having trouble with the analogy, since methods or functions seem more like verbs than variables (aren't these nouns?), the general idea of having a method handle various types of nouns is what type-less languages can do:

test = 'a person'
test2 = '[person, person, person,...]'
test3 = '1.618'
test4 = 'off the wall'
 

def agnostic_func(var): 
  if isinstance(var, Person):
     do_person_or_people_stuff(var)
  elif var is instance(var, float):
    do math stuff(var)
  else:
    print("eh? Say that again.")
     

$ agnostic_func(test)
> "I know her."
$ agnostic_func(test2)
> "I don't know them."
$ agnostic_func(test3)
> "Are you talking about phi?"
$ agnostic_func(test4)
> "eh? Say that again."

Inflection maybe similar to naming methods with their types, sometimes recognized with variant method signatures in typed languages:

func agnostic_funcPeopleArray(var)
func agnostic_funcFloat(var)

However, verb inflections carry voice (active vs. passive), mood (e.g. imperative vs. subjunctive), tense (is vs. was), and number (her vs. them); many of these aspects are not captured in the architecture of programming languages but are handled with programs e.g in NLP: Finding the tense of a sentence using Stanford's nlp library

gregory
  • 10,969
  • 2
  • 30
  • 42