[erlang-questions] comma-less lists and tuples
Richard A. O'Keefe
ok@REDACTED
Thu Sep 21 03:45:27 CEST 2006
Thomas Lindgren <thomasl_erlang@REDACTED> wrote:
Smalltalk has a similar notation, something like
"select: [foo bar baz] from: [tab1, tab2]
where: [xyz '=' {'+', [1 2 3 4]}]"'
As a Smalltalk user (still haven't finished my Smalltalk compiler;
too busy supervising students) who frequently consults the standard
and peers at the compiler's workings from time to time, I can tell
you that Smalltalk has no such syntax.
Smalltalk array LITERALS don't have commas, so
SQL select: #(foo bar baz)
from: #(tab1 tab2)
where: #(= xyz (+ 1 2 3 4))
would be entirely possible. However, there is no Smalltalk equivalent
of backquote. Suppose we wanted the name "bar", the name "tab2", and
the number "3" to be replaced by the values of Smalltalk variables.
In standard Smalltalk, you would have to write
SQL select: (Array with: #foo with: bar with: #baz)
from: (Array with: #tab1 with: tab2)
where: (Array with: #= with: #xyz with:
#(+ 1 2) , (Array with: three) , #(4))
where , is the infix concatenation operator.
Squeak Smalltalk has an "array literal with all elements evaluated"
syntax, using which we could write
SQL select: {#foo. bar. #baz}
from: {#tab1. tab2}
where: {#=. #xyz. {#+. 1. 2. three. 4}}
Squeak's '{' ... '.' ... '}' syntax is pretty much equivalent to
Erlang's '{' ... ',' ... '}' syntax, except for using full stops
instead of commas.
Actually, *native* Smalltalk style for really querying a data base
would be something like this:
((table1 cross: table2)
select: [:tuple | 1+2+3+4 = tuple xyz])
collect: [:tuple | {tuple foo. tuple bar. tuple ugh}]
The only languages in which this kind of thing is really easy are
the Lisp-family languages.
More information about the erlang-questions
mailing list