begin vs. do

Started by TedWalther, May 28, 2009, 10:45:50 PM

Previous topic - Next topic

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
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.

Kazimir Majorinc

#1
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.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

ale870

#2
"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">//http://www.rebol.com/docs/words/wdo.html)
--

newBert

#3
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 ?
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

HPW

#4
And people coming from autolisp use (constant 'progn begin)!

;-)
Hans-Peter

ale870

#5
Quote from: "HPW"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:



(if (= 1 1)
    (begin
        (println "This is a test")
        ) )


We could have:



(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")
        ) )
--

HPW

#6
QuoteThis 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">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?
Hans-Peter

cormullion

#7
Quote 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:


(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...

ale870

#8
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  :-)
--

cormullion

#9
Although I'm not convinced that an alternative is needed...



newLISP is fine the way it is (*)!



*edit: named parameters would be nice, though... :)

Lutz

#10
QuotenewLISP 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">http://www.newlisp.org/newlisp_manual.html#bind



scroll down to the last example.

ale870

#11
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 ;-)
--

cormullion

#12
Quote from: "Lutz"scroll down to the last example.


Yes, it's almost what I want, but:


(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... :)

Kazimir Majorinc

#13
Cormullion, I think you can find some ways around it. This is "proof of the concept" code only:


(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
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

cormullion

#14
Thanks, Kazimir!  



There are indeed http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2180">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).