uliwitness / Stacksmith

An intuitive software erector kit targeted at people new to programming, but with enough potential to stay useful once they've learned, inspired by HyperCard.
http://stacksmith.org
128 stars 13 forks source link

Add support for closures (to Forge) #102

Open uliwitness opened 4 years ago

uliwitness commented 4 years ago

We want an English-like syntax. Best I could come up with is

take <parameters>|nothing then
  -- commands go here
end take

and

take <parameters>|nothing then -- single command goes here

and

take <parameters>|nothing
then -- single command goes here

This reads fairly well when e.g. used in a function:

put sortedByName(myAddresses, take firstPerson, secondPerson then return firstPerson > secondPerson) into sortedAddresses
uliwitness commented 4 years ago

Alternate spelling that looks neat would be

take <parameters>|nothing and -- single command goes here

as well as

take <parameters>|nothing and do
  -- commands go here
end take

and maybe even

take <parameters>|nothing and
-- single command goes here

Considerations

  1. it might be confusing to have then re-used in something not conditional (will this lead to the same kind of confusion as people talking of "if loops"?)
  2. it might be confusing to have and that isn't a boolean operator, or do that isn't a do command. OTOH this could be used in many places where do used to be used, and we haven't implemented do yet.
  3. the way we distinguish a one-line take followed by a do command from a multi-line take is whether there's a return after the do or an argument, so no ambiguity.
  4. Scripters already have to learn the different ways to format a then for if, so using it here again kinda makes it more consistent.
uliwitness commented 4 years ago

Implementation Notes

If anyone has suggestions, it would be appreciated. Especially something that reads English in most cases, doesn't use nerdy terminology or big words, and fits into HyperTalk's "the value has the type, not the variable" (aka "everything is a string") world.

uliwitness commented 4 years ago

TBD - Can we make closure parameters more self-explanatory? Right now if a command expects errorCode, errorMessage in that order, and I reverse them, there's no way to detect that.