Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Scheme Programming Language

Was there a particular reason for "begin"?


hi

Was there a particular reason for "begin"? Wouldn't "reverse a list"
do, if someone wants right-to-left evaluation? "begin" obviously has
no scoping capability,  what's the point? thanks.

dillog@gmail.com wrote:
> Was there a particular reason for "begin"? Wouldn't "reverse a list"
> do, if someone wants right-to-left evaluation? "begin" obviously has
> no scoping capability,  what's the point? thanks.

(define (d x) (display x) x)
(define (b . x) (car (reverse x)))

Both B and BEGIN evaluate all of their arguments and both return the
normal form of their last argument.

But:

(b (d 1) (d 2) (d 3))

may display any permutation of {1,2,3} as its side effect while

(begin (d 1) (d 2) (d 3))

will always display 123.

--
Nils M Holm <n m h @ t 3 x . o r g> -- http://t3x.org/nmh/

On Apr 5, 4:24 pm, Nils M Holm <before-2007-07@online.de> wrote:

Wow, does that I mean I don't need a special syntax case for
begin...cool.

Actually, you do have to implement BEGIN as syntax, because
B is /not/ equal to BEGIN.

(begin x y z)

is in fact equal to

((lambda (ignore) z) ((lambda (ignore) y) x))

--
Nils M Holm <n m h @ t 3 x . o r g> -- http://t3x.org/nmh/

<dillog@gmail.com> wrote:
> hi

> Was there a particular reason for "begin"? Wouldn't "reverse a list"
> do, if someone wants right-to-left evaluation? "begin" obviously has
> no scoping capability,  what's the point? thanks.

Here is something I noticed about begin...

I am writing little evaluators in Scheme to express the semantics of
language constructs. My evaluators do not recognize a begin expression
because I want to keep them as primitive as possible to see what core
features a new feature depends on. However, when I want to test an
assignment construct, I usually want to have another expression follow the
assignment, at least to make sure the assignment worked.

(let ((x 1))
  (begin (set! x 2) x))

(let ((x 1))
  ((lambda (d) x) (set! x 2)))

(let ((seq (lambda (e1 e2) ((lambda (d) e2) e1))))
  (let ((x 1))
    (seq (set! x 2) x)))

;----

(let ((x 0) (y 0))
  (begin (set! x 1) (set! y 2) (+ x y)))

(let ((x 0) (y 0))
  ((lambda (d) ((lambda (d) (+ x y)) (set! y 2))) (set! x 1)))

(let ((seq (lambda (e1 e2) ((lambda (d) e2) e1))))
  (let ((x 0) (y 0))
    (seq (set! x 1) (seq (set! x 2) (+ x y)))))

That is, to simulate evaluating two expressions in sequence, I pass the
first expression to a procedure whose body is the second expression and
whose dummy parameter is bound to value of the first expression.

My guess is (begin e1 ... en) is a nested sequence of procedure applications
with dummy parameters.

On Apr 8, 12:15 am, "Marlene Miller" <marlenemil@worldnet.att.net>
wrote:

> (let ((seq (lambda (e1 e2) ((lambda (d) e2) e1))))
>   (let ((x 1))
>     (seq (set! x 2) x)))

This may return 1 or 2.  You need another way to sequence your
operations.

Aziz,,,

"Abdulaziz Ghuloum" wrote.

> "Marlene Miller" wrote:

> > (let ((seq (lambda (e1 e2) ((lambda (d) e2) e1))))
> >   (let ((x 1))
> >     (seq (set! x 2) x)))

> This may return 1 or 2.  You need another way to sequence your
> operations.

> Aziz,,,

Oops.

(let ((x 0) (y 0))
  (let ((d (set! x 1)))
    (let ((d (set! y 2)))
      (let ((d (+ x y)))
        d))))

Or currying

(let ((x 0) (y 0))
  (((lambda (d)
      (lambda (d)
        (lambda (d) d)))
    (+ x y))
  (set! x 1))
(set! y 2))

(define s
  (lambda (n)
    (if (= n 1)
        (lambda (d) d)
        (lambda (d) (s (- n 1))))))

(let ((x 0) (y 0))
  ((((s 3) (set! x 1)) (set! y 2)) (+ x y)))

Marlene Miller <marlenemil@worldnet.att.net> wrote:
> Or currying

> (let ((x 0) (y 0))
>   (((lambda (d)
>       (lambda (d)
>         (lambda (d) d)))
>     (+ x y))
>   (set! x 1))
> (set! y 2))

I guess what you meant was:

(let ((x 0) (y 0))
  (((lambda (d)
      (lambda (d)
        (lambda (d) d)))
     (set! y 2))
    (set! x 1))
   (+ x y))

> (define s
>   (lambda (n)
>     (if (= n 1)
>         (lambda (d) d)
>         (lambda (d) (s (- n 1))))))

> (let ((x 0) (y 0))
>   ((((s 3) (set! x 1)) (set! y 2)) (+ x y)))

--
Nils M Holm <n m h @ t 3 x . o r g> -- http://t3x.org/nmh/
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc