english-script icon indicating copy to clipboard operation
english-script copied to clipboard

Syntactic ambiguity may need to be resolved

Open jarble opened this issue 8 years ago • 3 comments

In this sample code, I noticed that function parameters were not clearly distinguished from other parts of functions, causing some confusion:

To check if person is online on Skype:
    Skype.checkStatus(person) //Is 'Skype' a parameter of this function?
    if result is "online": return yes
    else return no
End

This code would be easier to read if the parameters were explicitly specified, like this:

To check if 'person' is online on Skype:
    Skype.checkStatus(person)
    if result is "online": return yes 
    else return no
End

This describes the program's intention much more clearly, ensuring that no parameters are created accidentally.

jarble avatar Dec 08 '15 13:12 jarble

Well this is an extreme example of a 'function', containing 'if' and 'is'. It's more like a pattern to be matched. You are right that it would help to mark the 'loose' parts of the pattern. However ideally the matching+marshalling engine should also match: determine whether Peter is currently on Skype >> check if person is online on Skype This would be the very long-term goal. For now:

Usually parameters are all 'nouns' in a function declaration: to blubber some foo in bar: print foo

pannous avatar Dec 08 '15 14:12 pannous

To clarify: a variable/object matches a parameter, if it is of matching type:

to notify a person:
   send 'hi' to person

Peter is a person
notify Peter             // ok ... (if 'send' is defined somewhere ...)

foo is a bug
notify foo           // error/question: how to notify bugs? Is foo a person? Are bugs persons?

pannous avatar Dec 08 '15 14:12 pannous

To finally address your question: Skype is a singleton, so it's not really a parameter, only there for matching. Distinction between singletons / parameters : Upper case? Context? Quotes?

I'd say context.

Actually they don't need extra treatment: Rule: If a parameter is missing but available in the context, take it.

So

to eat a meal: say 'yummy ' + meal
a hamburger is a meal
x=new hamburger
eat !        // x consumed  'yummy hamburger'

pannous avatar Dec 08 '15 14:12 pannous