Page 1 of 1
begin vs. do
Posted: Fri May 29, 2009 5:45 am
by TedWalther
I was just reading the wikipedia article on REXX tonight, after reading their article on COBOL. I was struck with how elegant REXX is. Not as LISP, mind you, but it had a couple nice things. I believe the (begin... construct came from the BASIC language. Right? In REXX, "do" serves the same role. If it isn't a reserved word, (I believe it isn't) I will start doing (constant 'do begin) and starting using (do...) in my code instead of (begin...)
Lutz, thanks for incorporating those $prefix type changes! In the next couple months I will try to implement an OpenBSD "port", or "package", of newlisp. There used to be one, I don't know why it was dumped.
Ted
Posted: Fri May 29, 2009 8:38 am
by Kazimir Majorinc
I think begin is from Algol and came here through Pascal and then Scheme but I agree that do fits better - it is shorter, similar to dolist, dotimes and brothers and it doesn't beg for end. It appears that author of the Clojure thought same way.
Posted: Sat May 30, 2009 10:52 pm
by ale870
"begin" is used in many very descriptive languages (even ada, modula2 and modula3, and even other "modern" language like pl/sql (oracle) based on ada, use that so long construct).
I agree with you, "do" fits better, but warning: it could be "confused" with something like "eval". In fact there are other functional languages that use it in this way (see Rebol at:
http://www.rebol.com/docs/words/wdo.html)
Posted: Sun May 31, 2009 8:07 am
by newBert
I think do is ambiguous. In some languages like Lua, Euphoria it is used to begin a block but it probably evals the block too. In any rate one would think so.
dotimes and dolist (in NewLISP) gives me the same impression. I think that begin is more expressive even if we don't find the correlated end, useless in NewLISP because of the (closing/ending) brackets.
We could say "block" instead of "begin" but IMHO it's not a very pretty word
;-)
P.S.: finally a block with begin is evaluated too. So ... do or begin ?
Posted: Sun May 31, 2009 9:24 am
by HPW
And people coming from autolisp use (constant 'progn begin)!
;-)
Posted: Sun May 31, 2009 1:12 pm
by ale870
HPW wrote:And people coming from autolisp use (constant 'progn begin)!
;-)
This is an important point: even if newLisp is not Lisp, I think if there are some "compatibilities" they could simplify user "migration".
"block" could fit very well, but if the starting point of this discussion was finding a shorter word than "begin", I think "block" will cause incompatibilities but will not give a big benefit.
I think we could really round the corner with a hard solution: why don't we try to use a symbol like "^^" (or any other), or we could find a single word token like "b".
C language is good even for its code, and they use "{"
See here:
Code: Select all
(if (= 1 1)
(begin
(println "This is a test")
) )
We could have:
Code: Select all
(if (= 1 1)
(b
(println "This is a test")
) )
(if (= 1 1)
(^^
(println "This is a test")
) )
(if (= 1 1)
(::
(println "This is a test")
) )
Posted: Sun May 31, 2009 3:35 pm
by HPW
This is an important point: even if newLisp is not Lisp, I think if there are some "compatibilities" they could simplify user "migration".
I have no problem, that newLISP does have 'begin' for blocking code.
For me it is in the best sense of 'bottom-up design' described by Paul Graham in one of his essays:
http://www.paulgraham.com/progbot.html
So I am sure every newLISP'er user uses newLISP to make his own special language which gets the best fit to solve his own programming task.
So when I want to have 'progn' or 'do' what's the problem to switch to them with a one-liner?
Posted: Sun May 31, 2009 5:11 pm
by cormullion
think we could really round the corner with a hard solution: why don't we try to use a symbol like "^^" (or any other), or we could find a single word token like "b".
I think the only typographical asset currently under-utilized in newLISP is the opening square bracket... Perhaps, one day, in Lutz' careful hands, it could do something wonderful or surprising on its own, not just introducing [ text ], [ cmd ]. But it would be a shame to see a valuable resource used just to provide a simple synonym for 'begin'...
Oh, it also lets you do those weird symbol names:
Code: Select all
(constant (sym "[Please do all the following expressions in order:]") begin)
...
([Please do all the following expressions in order:] (println "hi" ) (println "there"))
hi
there
Me, I like
begin. Particularly since you don't have to find a matching
end... You can type it with confidence, knowing that in just a few seconds you can start writing some code that actually does some work...
Posted: Sun May 31, 2009 5:28 pm
by ale870
Basically I agree with you cormullion, in fact I don't like to find matching "end" from "begin".
I think Lutz could find a "special" symbol (not like open/close). Close must be like the standard: ")" (as every other function).
I really like newLisp for functions usage, symbols usage, etc... (against imperative languages).
SO if we want (Lutz wants!) to find an alternative, we MUST avoid to break newLisp fashion/magic :-)
Posted: Sun May 31, 2009 5:55 pm
by cormullion
Although I'm not convinced that an alternative is needed...
newLISP is fine the way it is (*)!
*edit: named parameters would be nice, though... :)
Posted: Sun May 31, 2009 8:08 pm
by Lutz
newLISP is fine the way it is (*)!
*edit: named parameters would be nice, though... :)
thanks ;) and you could use this:
http://www.newlisp.org/newlisp_manual.html#bind
scroll down to the last example.
Posted: Sun May 31, 2009 8:22 pm
by ale870
Hey Lutz, you are running at the light's speed!!! :-)
Example in the manual about binding (arguments) is great!
(I will steal that and put it in my blog ;-)
Posted: Sun May 31, 2009 8:38 pm
by cormullion
Lutz wrote:scroll down to the last example.
Yes, it's almost what I want, but:
Code: Select all
(context 'My-cool-context)
(define-macro (foo)
(local (len width height)
(bind (args) true)
(println "len:" len " width:" width " height:" height)))
(context MAIN)
(My-cool-context:foo (My-cool-context:width (+ 15 5)) (My-cool-context:height 30) (My-cool-context:len 10))
- in my view - less than perfect... :)
Posted: Mon Jun 01, 2009 9:56 am
by Kazimir Majorinc
Cormullion, I think you can find some ways around it. This is "proof of the concept" code only:
Code: Select all
(define (decontext-AL x)
(list (sym (slice (string (first x))
(+ (or (find ":"
(string (first x)))
-1)
1)))
(last x)))
(context 'My-cool-context)
(define-macro (foo)
(local (len width height)
(bind (map MAIN:decontext-AL (args)) true) ; nil for macro!
(println " len: " len " width: " width " height: " height)))
(foo (width (+ 15 5)) (height 30) (len 10))
; len: 10 width: 20 height: 30
(context MAIN)
(My-cool-context:foo (width (+ 15 5)) (height 30) (len 10))
; len: 10 width: 20 height: 30
Posted: Mon Jun 01, 2009 7:42 pm
by cormullion
Thanks, Kazimir!
There are indeed
many workrounds, and yours is more excellent than most of those, but it remains a workround nonetheless.
This (now becoming off topic, sorry! :)) issue isn't really related to functionality, because there are many ways to pass some kind of label with arguments to functions. It's mostly - for me at least - related to readability. So workrounds aren't that important; they don't make things much more readable, and introduce more code (and presumably slow down execution speed).