Lisp and Scheme 
Author Message
 Lisp and Scheme

Hi,
I do not want to start a war or be flamed. I'm a CS & Software Eng student
and last year (in the first year) I learned Scheme. I liked it very much but
I always made a question to myself. If Scheme is a dialect of Lisp why learn
Scheme if we can learn Lisp directly? What is the advantage of Scheme over
Lisp or what is best ...???
Again, please I want honest answer, I'm not a troll.

Thx very much,
Best regards,

--
Paulo J. Matos aka PDestroy
http://www.*-*-*.com/
ICQ UIN - 361853

--
You will do foolish things, but do them with enthusiasm.
           - Colette



Wed, 16 Apr 2003 04:40:30 GMT  
 Lisp and Scheme

Quote:
> Hi,
> I do not want to start a war or be flamed. I'm a CS & Software Eng student
> and last year (in the first year) I learned Scheme. I liked it very much but
> I always made a question to myself. If Scheme is a dialect of Lisp why learn
> Scheme if we can learn Lisp directly? What is the advantage of Scheme over
> Lisp or what is best ...???
> Again, please I want honest answer, I'm not a troll.

They are designed for different purposes.

Scheme has far fewer idiocyncracies than Lisp.  This makes it easier
to express many complicated design paradigms in scheme without getting
bogged down in the details of implementation.

Common Lisp has a number of things in it that have been added because
they were `useful' rather than `illustrative'.  It is also an amalgam
of several variants of Lisp that were popular at the time it was
designed.  It has rich libraries that make it easy to write very
complicated programs with little code.

I cannot say that one is `better' than the other.  It would depend on
what you are doing.  In my job, I use Common Lisp because there is a
vendor that supports it on all the platforms we deliver a product on.
At home I use MIT Scheme because I like it and I am fairly familiar
with the implementation details.

You should learn them both.

Quote:
> Thx very much,
> Best regards,

> --
> Paulo J. Matos aka PDestroy
> http://www.pdestroy.net
> ICQ UIN - 361853

> --
> You will do foolish things, but do them with enthusiasm.
>            - Colette

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


Wed, 16 Apr 2003 09:55:21 GMT  
 Lisp and Scheme

Quote:

> I cannot say that one is `better' than the other.  It would depend on
> what you are doing.  In my job, I use Common Lisp because there is a
> vendor that supports it on all the platforms we deliver a product on.
> At home I use MIT Scheme because I like it and I am fairly familiar
> with the implementation details.

> You should learn them both.

I prefer CL, myself, but I'm in the process of learning Scheme just
on general principle and so I can effectively code cool toys for my
Visor using LispMe.  In fact, I subscribed to this group yesterday, I
think, which leads me to my first question:

In Common Lisp, this is legal, and lets me play with generators and
such:

(let ((x 1))
  (defun gen ()
    (incf x)))

However, the equivalent Scheme code is illegal:

(let ((x 1))
  (define gen
    (lambda ()
      (set! x (+ x 1))
      x)))

This works, though:

(define gen
  (let ((x 1))
    (lambda ()
      (set! x (+ x 1))
      x)))

Why is this?

--
vsync
http://quadium.net/ - last updated Fri Oct 27 16:38:34 PDT 2000
(cons (cons (car (cons 'c 'r)) (cdr (cons 'a 'o))) ; Orjner
      (cons (cons (car (cons 'n 'c)) (cdr (cons nil 's))) nil))



Wed, 16 Apr 2003 10:18:00 GMT  
 Lisp and Scheme


Quote:
> In Common Lisp, this is legal, and lets me play with generators and
> such:

> (let ((x 1))
>   (defun gen ()
>     (incf x)))

You can do that and it's useful?  Eek!  So much for lexical scoping...

Quote:
> However, the equivalent Scheme code is illegal:

> (let ((x 1))
>   (define gen
>     (lambda ()
>       (set! x (+ x 1))
>       x)))

But this is legal:

(let ((x 1))
  (set! gen
    (lambda ()
      (set! x (+ x 1))
      x)))

It's useless, of course.  It doesn't return anything.

This is legal, too:

(let ((x 1))
  (define gen
    (lambda ()
      (set! x (+ x 1))
      x))
  gen)

It returns a function, which was stored temporarily in "gen".  So you
could store it in an outer scope variable:

(define gg
  (let ((x 1))
    (define gen
      (lambda ()
        (set! x (+ x 1))
        x))
    gen))

Why bother with the inner variable?

(define gg
  (let ((x 1))
    (lambda ()
      (set! x (+ x 1))
      x)))

Which is what you got:

Quote:
> This works, though:

> (define gen
>   (let ((x 1))
>     (lambda ()
>       (set! x (+ x 1))
>       x)))

> Why is this?

Think of what define (and let) mean.  They're just shortcuts.

(define x y) ... actually means
((lambda (x) ... ) y)

(let ((a x) (b y) (c z)) ... )  actually means
((lambda (a b c) ...) x y z)

So your example actually means:

(
 (lambda (gen)  # create an environment with a binding called gen
   (do something with gen)
   (do more things with gen))

 #here's the value of gen
 ((lambda (x)  #create an environemnt with a binding x

    #here's the actual value for gen -- a function
    (lambda ()
      (set! x (+ x 1))
      x)

    ) 1)  #x is 1

)



Wed, 16 Apr 2003 11:15:44 GMT  
 Lisp and Scheme
[A much shorter answer than the one posted...]

Quote:

> In Common Lisp, this is legal, and lets me play with generators and
> such:

> (let ((x 1))
>   (defun gen ()
>     (incf x)))

In CL, a defun always binds a global name which makes the above
sensisble.

Quote:
> However, the equivalent Scheme code is illegal:

> (let ((x 1))
>   (define gen
>     (lambda ()
>       (set! x (+ x 1))
>       x)))

In Scheme, define is [roughly] used for defining a name in the scope
it appears in so here you bind gen in the environment that has x
bound, but you return no value.

Quote:
> This works, though:

> (define gen
>   (let ((x 1))
>     (lambda ()
>       (set! x (+ x 1))
>       x)))

> Why is this?

Because here you have a lambda expression that is in the scope of the
x.  This is sort of like the equivalent CL code with defvar instead of
the define - the result function would have its correct x binding but
in CL you'll have to use funcall with such a variable.

--
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!



Wed, 16 Apr 2003 13:17:45 GMT  
 Lisp and Scheme

Quote:

> In Common Lisp, this is legal, and lets me play with generators and
> such:

> (let ((x 1))
>   (defun gen ()
>     (incf x)))

> However, the equivalent Scheme code is illegal:

> (let ((x 1))
>   (define gen
>     (lambda ()
>       (set! x (+ x 1))
>       x)))

In standard scheme (r5rs), that expression is legal, although it has
no effect.  In scheme, define creates bindings in the local lexical
scope.  In your cl example, defun is used inside a let to create a
binding visible outside of the let.  Scheme is more rigidly lexically
scoped and has no equivalent expression.  If a binding for gen already
exists, however, then the following scheme expression is legal and
similar in effect to the cl expression:

 (let ((x 1))
   (set! gen
     (lambda ()
       (set! x (+ x 1))
       x)))

Quote:
> This works, though:

> (define gen
>   (let ((x 1))
>     (lambda ()
>       (set! x (+ x 1))
>       x)))

And that would usually be preferred.

-al



Wed, 16 Apr 2003 13:22:48 GMT  
 Lisp and Scheme

Quote:

> > However, the equivalent Scheme code is illegal:

> > (let ((x 1))
> >   (define gen
> >     (lambda ()
> >       (set! x (+ x 1))
> >       x)))

> In standard scheme (r5rs), that expression is legal, although it has
> no effect.

Actually, it is not even legal - the internal define should be
equivalent to a letrec:

  (let ((x 1))
    (letrec ((gen (lambda () ...)))
      ))

which is illegal since the letrec's body should contain at least one
expression.

--
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!



Wed, 16 Apr 2003 13:57:17 GMT  
 Lisp and Scheme

Quote:
> I do not want to start a war or be flamed. I'm a CS & Software Eng student
> and last year (in the first year) I learned Scheme. I liked it very much but
> I always made a question to myself. If Scheme is a dialect of Lisp why learn
> Scheme if we can learn Lisp directly? What is the advantage of Scheme over
> Lisp or what is best ...???
> Again, please I want honest answer, I'm not a troll.

whenever you suggest evaluation, you either must suggest criteria or accept
the answer "it all depends".  the more honest your criteria the more honest an
answer...

thi



Wed, 16 Apr 2003 16:20:53 GMT  
 Lisp and Scheme

Quote:
>Hi,
>I do not want to start a war or be flamed. I'm a CS & Software Eng student
>and last year (in the first year) I learned Scheme. I liked it very much but
>I always made a question to myself. If Scheme is a dialect of Lisp why learn
>Scheme if we can learn Lisp directly? What is the advantage of Scheme over
>Lisp or what is best ...???

Well, there's no such thing as "Lisp" that isn't a
dialect of Lisp. Common Lisp is often regarded as
_the_ Lisp or the standard dialect of Lisp, but it
still is just one dialect. This is because the term
Lisp nowadays refers to a family of languages that
are based on the original Lisp, and no longer refers
to one specific language. As for an advantage of
Scheme over Common Lisp, it's simpler, more uniform,
and in my opinion more powerful as well. It however
has no stadardized library or object system, which
limits its usefulness for large-scale software
engineering.


Wed, 16 Apr 2003 17:50:39 GMT  
 Lisp and Scheme

Quote:


>> In Common Lisp, this is legal, and lets me play with generators and
>> such:
>> (let ((x 1))
>>   (defun gen ()
>>     (incf x)))
>You can do that and it's useful?  Eek!  So much for lexical scoping...

Well if my understanding is correct, the function is created in
the lexical scope of let, but is bound to gen at the top-level
environment. I guess it's useful, if you want to have several
top-level functions to share a lexical environment. The above
is easily written as:

(define gen
  (let ((x 1))
    (lambda ()
      (inc! x))))

but something like this isn't so trivially transformed:

(let ((x 1))
  (defun gen ()
    (incf x))
  (defun gen2 ()
    (decf x)))



Wed, 16 Apr 2003 18:05:32 GMT  
 Lisp and Scheme

Quote:

> ...
>In Common Lisp, this is legal, and lets me play with generators and
>such:

>(let ((x 1))
>  (defun gen ()
>    (incf x)))

>However, the equivalent Scheme code is illegal:

>(let ((x 1))
>  (define gen
>    (lambda ()
>      (set! x (+ x 1))
>      x)))

i don't think it's illegal (might depend on the implementation), but
it won't have the effect you expected:  afaik nested defines in scheme
establish the name in the local block, so with your define you make
gen visible only in the block starte with let, i.e. it's inaccessible
from outside.

Quote:
>This works, though:

>(define gen
>  (let ((x 1))
>    (lambda ()
>      (set! x (+ x 1))
>      x)))

>Why is this?

the lambda is the last expression in the let block, thus its value,
which gets bound to gen

hs



Wed, 16 Apr 2003 09:42:07 GMT  
 Lisp and Scheme

Quote:

> You should learn them both.

Could anyone suggest a good reference for learning Common LISP for someone
who's already pretty well versed in Scheme?

Richard



Wed, 16 Apr 2003 23:43:57 GMT  
 Lisp and Scheme

Quote:


> > You should learn them both.

> Could anyone suggest a good reference for learning Common LISP for someone
> who's already pretty well versed in Scheme?

I'm probably not the right one to anser this question (being myself a bit
advanced beginner in both). But I guess that the following books are
quite well for good Scheme programmers.

Paradigms of Artificial Intelligence Programming: Case Studies in
Common Lisp, Peter Norvig.

for delving into Makros
On Lisp; Advanced Techniques for Common Lisp

Common Lisp the language (reference)

For implementation details
Lisp in small pieces.

You too might want to download the Hyperspec.

Hope more advanced Scheme users like me will confirm that these things
are worth it;-)

Friedrich

--
for e-mail reply remove all after .com



Wed, 16 Apr 2003 23:46:34 GMT  
 Lisp and Scheme

Quote:
> Could anyone suggest a good reference for learning Common LISP for someone
> who's already pretty well versed in Scheme?

Here are a couple of resources:

  Common Lisp: A Gentle Introduction to Symbolic Computation
  http://www.cs.cmu.edu:80/afs/cs.cmu.edu/user/dst/www/LispBook/index.html

  Successful Lisp
  http://psg.com/~dlamkins/left/sl/sl.html

Paolo
--
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/



Thu, 17 Apr 2003 05:13:48 GMT  
 Lisp and Scheme

Quote:

> but something like this isn't so trivially transformed:

> (let ((x 1))
>   (defun gen ()
>     (incf x))
>   (defun gen2 ()
>     (decf x)))

In Dylan I'd just do:

============================================
module: incdec

define constant (gen, gen2) =
  block()
    let x = 1;
    values(method () x := x + 1 end,
           method () x := x - 1 end)
  end;

define function main()
  let pp = method(f) format-out("x = %d\n", f()) end;
  pp(gen);
  pp(gen);
  pp(gen);
  pp(gen2);
end function main;

main();
============================================
x = 2
x = 3
x = 4
x = 3
============================================

My old copy of MacGambit (1.9.1) doesn't have it, but I thought recent
Schemes had the same sort of multiple-value return construct?

-- Bruce



Thu, 17 Apr 2003 06:42:15 GMT  
 
 [ 23 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Lisp syntax : Lisp objects :: Scheme syntax : characters

2. lisp (or scheme) to forth compiler

3. Which one, Lisp or Scheme?

4. Which one, Lisp or Scheme

5. Is there a Lisp to Scheme converter?

6. auto-translate Lisp to Scheme?

7. Lisp Pointers: Scheme: TNG

8. Benchmarking results for modern Lisps and Schemes

9. translation from Common-Lisp to Scheme

10. -snif- my first real post Lisp and Scheme

11. LISP to Scheme Translators

12. Differences between common lisp and scheme

 

 
Powered by phpBB® Forum Software