From Swym Wiki
Jump to: navigation, search

Swym supports the English-language concepts of "all", "some", and "none", with a set of functions named, surprisingly enough, all, some, and none.

 if[ bob.family.all.likes(bob) ]
   print("bob is pretty popular!")
 if[ bob.family.none.likes(bob) ]
   print("bob is really unpopular!")

These functions are very closely related to the each function: they take an array, and return the contents of that array packaged in a special kind of multi-value called a 'quantifier'. Recall that the box operator turns a normal multi-value into an array? Well, the box operator will 'resolve' a quantifier into a single boolean value.

'greeting' = "hello"
  'arrayresult' = [ greeting.each == "e" ] // => [false, true, false, false, false].
  'boolresult' = [ greeting.some == "e" ] //  => (false||true||false||false||false) => true.

It's not legal to have an expression that involves both a quantifier and a multi-value.

 [ each~a == some~b ] // error! (You probably meant all~a.)

However, it is legal to have multiple quantifiers in the same expression. They are resolved in the same order they appear in the source code:

'greeting' = "hello"
  'alphabet' = "abcdefghijklmnopqrstuvwxyz"
  'allsome' = [ all~greeting == some~alphabet ] // true - all letters in greeting appear somewhere in alphabet.
  'someall' = [ some~alphabet == all~greeting ] // false - no one letter of alphabet matches all letters in greeting.

PS: Logicians in the audience may be surprised to see an AND ('all'), OR ('some') and NOR ('none') quantifier, but no corresponding NAND quantifier. It's absent, essentially, because English doesn't have a good word for it. The natural way to express such a quantifier in English would be rephrase it to use "all" or "some". Swym programmers are encouraged to do the same:

 if( not[ all~people.paidTaxes ] ) {...}
 if[ some~people.!paidTaxes ] {...}
Personal tools