Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

LispMe Question
I've been following along with an article from an IBM site on using
functions as arguments, function-generating functions, and anonymous
functions. Anyway, I tried a simple program in LispMe yesterday and got
an error, while the same input fed into mit-scheme running on Linux
worked just fine. Warning: I am very new to Scheme.

Here are the lines of code:

(define square (lambda (x) (* x x)))
(define my-test-data '(1 2 3 4 5 6))
(define list-of-squares (map square my-test-data))

I put these into a memo.  Next I started up LispMe and loaded the
standard library.  Finally I loaded my memo, but LispMe returns a
runtine error: Sucked into black hole. That's bad, right?

I try typing (display list-of-squares) on the input line and press the
eval key, and the system returns a compiler error: Undefined name
list-of-squares. However, I do find list-of-squares on the Symbols drop
down list.

Any suggestions would be appreciated.


TIA, Steve


Report this thread to moderator Post Follow-up to this message
Old Post
jsgrahamus@yahoo.com
04-09-05 01:58 AM


Re: LispMe Question
jsgrahamus@yahoo.com wrote:
> I've been following along with an article from an IBM site on using
> functions as arguments, function-generating functions, and anonymous
> functions. Anyway, I tried a simple program in LispMe yesterday and
got
> an error, while the same input fed into mit-scheme running on Linux
> worked just fine...

It works just fine in PLT Scheme as well, so I suspect LispMe doesn't
quite conform to standard Scheme semantics.  As I don't have a Palm I
can't test this code, but perhaps the following change will work:

(define list-of-squares (lambda () (map square my-test-data)))

This defines list-of-squares as a function that returns a list of
squares, and so delays accessing the definitions which seems to cause
the problems.

HTH,
Noel


Report this thread to moderator Post Follow-up to this message
Old Post
noelwelsh@gmail.com
04-09-05 08:57 PM


Re: LispMe Question
jsgrahamus@yahoo.com wrote:
> I've been following along with an article from an IBM site on using
> functions as arguments, function-generating functions, and anonymous
> functions. Anyway, I tried a simple program in LispMe yesterday and
got
> an error, while the same input fed into mit-scheme running on Linux
> worked just fine. Warning: I am very new to Scheme.
>
> Here are the lines of code:
>
> (define square (lambda (x) (* x x)))
> (define my-test-data '(1 2 3 4 5 6))
> (define list-of-squares (map square my-test-data))
>
> I put these into a memo.  Next I started up LispMe and loaded the
> standard library.  Finally I loaded my memo, but LispMe returns a
> runtine error: Sucked into black hole. That's bad, right?
>
> I try typing (display list-of-squares) on the input line and press
the
> eval key, and the system returns a compiler error: Undefined name
> list-of-squares. However, I do find list-of-squares on the Symbols
drop
> down list.
>
> Any suggestions would be appreciated.
>
>
> TIA, Steve


Report this thread to moderator Post Follow-up to this message
Old Post
noelwelsh@gmail.com
04-09-05 08:57 PM


Re: LispMe Question
jsgrahamus@yahoo.com wrote:

> I've been following along with an article from an IBM site on using
> functions as arguments, function-generating functions, and anonymous
> functions. Anyway, I tried a simple program in LispMe yesterday and got=

> an error, while the same input fed into mit-scheme running on Linux
> worked just fine. Warning: I am very new to Scheme.
>=20
> Here are the lines of code:
>=20
> (define square (lambda (x) (* x x)))
> (define my-test-data '(1 2 3 4 5 6))
> (define list-of-squares (map square my-test-data))
>=20
> I put these into a memo.  Next I started up LispMe and loaded the
> standard library.  Finally I loaded my memo, but LispMe returns a
> runtine error: Sucked into black hole. That's bad, right?

On <http://www.lispme.de/lispme/doc/lm_err.htm> you can see what
the various messages mean:

[R9] Sucked into black hole

During evaluation of the local definitions in a letrec form, the
value of one of the variables just being bound was accessed. An
access to the value of any variable in the binding list will
cause this error while the expressions to initialize these
variables are evaluated. These variables may be used inside
a lambda or delay special form, as in this case their value
will not be needed during evaluation of these forms.

At first this seems strange, but if you examine how LispMe
interprets the define, this begin to make sense:

<http://www.lispme.de/lispme/doc/lm_...htm#desc_define>

In LispMe, every name used must have been defined before, so
every variable used in expri must have been defined in the
same binding group (see loading), in a previously loaded memo
or manual definition before, or in the case of a local
definition, in the enclosing construct. In fact, a group of
definitions (like a memo to be loaded, or a list of definitions
enclosed in a begin expression entered into the command line)
or a group of local definitions is treated like a letrec binding
group; this means that every name used in this group must have
been defined before or must be defined in this binding group
(for mutual recursive definitions). This assures that every
name can be statically resolved at compile time and there's
no symbol table left to be checked at runtime.

That is, top-level defines in LispMe behaves the same as internal
defines does in "normal" Scheme implementations.

> (define square (lambda (x) (* x x)))
> (define my-test-data '(1 2 3 4 5 6))
> (define list-of-squares (map square my-test-data))

Try this in stead:

(define square (lambda (x) (* x x))
(define my-test-data '(1 2 3 4 5 6))
(define list-of-squares (lambda () (map square my-test-data))

and then write

(list-of-squares)

in the REPL.

--=20
Jens Axel S=F8gaard





Report this thread to moderator Post Follow-up to this message
Old Post
Jens Axel Søgaard
04-10-05 01:57 AM


Re: LispMe Question
On Sat, 09 Apr 2005 22:10:24 +0200, Jens Axel Søgaard wrote:

> jsgrahamus@yahoo.com wrote:
> 
>
> On <http://www.lispme.de/lispme/doc/lm_err.htm> you can see what
> the various messages mean:
>
>    [R9] Sucked into black hole
>
>    During evaluation of the local definitions in a letrec form, the
>    value of one of the variables just being bound was accessed. An
>    access to the value of any variable in the binding list will
>    cause this error while the expressions to initialize these
>    variables are evaluated. These variables may be used inside
>    a lambda or delay special form, as in this case their value
>    will not be needed during evaluation of these forms.
>
> At first this seems strange, but if you examine how LispMe
> interprets the define, this begin to make sense:
>
>    <http://www.lispme.de/lispme/doc/lm_...htm#desc_define>
>
>    In LispMe, every name used must have been defined before, so
>    every variable used in expri must have been defined in the
>    same binding group (see loading), in a previously loaded memo
>    or manual definition before, or in the case of a local
>    definition, in the enclosing construct. In fact, a group of
>    definitions (like a memo to be loaded, or a list of definitions
>    enclosed in a begin expression entered into the command line)
>    or a group of local definitions is treated like a letrec binding
>    group; this means that every name used in this group must have
>    been defined before or must be defined in this binding group
>    (for mutual recursive definitions). This assures that every
>    name can be statically resolved at compile time and there's
>    no symbol table left to be checked at runtime.
>
> That is, top-level defines in LispMe behaves the same as internal
> defines does in "normal" Scheme implementations.
> 
>
> Try this in stead:
>
>    (define square (lambda (x) (* x x))
>    (define my-test-data '(1 2 3 4 5 6))
>    (define list-of-squares (lambda () (map square my-test-data))
>
> and then write
>
>    (list-of-squares)
>
> in the REPL.

Thanks, this worked!  I don't understand why the addition of the lambda
made it work.  I also don't understand why a (display list-of-squares)
does not display the list of squares.  Instead it yields [clos 0].

This is a little different from what I've been used to for the last many
years.


Steve Graham

Report this thread to moderator Post Follow-up to this message
Old Post
Steve Graham
04-10-05 09:00 PM


Re: LispMe Question
Steve Graham wrote:

> On Sat, 09 Apr 2005 22:10:24 +0200, Jens Axel S=F8gaard wrote:
 
>=20
>=20
> Thanks, this worked!  I don't understand why the addition of the lambda=

> made it work.  I also don't understand why a (display list-of-squares)
> does not display the list of squares.  Instead it yields [clos 0].
>=20
> This is a little different from what I've been used to for the last man=
y
> years.

Unlike a standard Scheme interpreter LispMe rewrites the
original three defines to

(letrec ((square          (lambda (x) (* x x)))
(my-test-data    '(1 2 3 4 5 6))
(list-of-squares (map square my-test-data))
(list-of-squares))

The problem is that letrec specifies that one should be able
to evaluate all the right hand sides without refering to
the left hand sides.  Since the right hand side of list-of-squares
refer to my-test-data, without knowing the result of my-test-data.

The revised version is rewritten to:

(letrec ((square          (lambda (x) (* x x)))
(my-test-data    '(1 2 3 4 5 6))
(list-of-squares (lambda () (map square my-test-data)))
list-of-squares)

Now the right hand side is a closure, which can be evaluated
without knowing the result of my-test-data.

But, since list-of-squares now is function, just evaluating

list-of-squares

will give a function (represented as a closure). This explains
why your (display list-of-squares) writes [clos 0].

To get the actual squares, you need to call the function as
(list-of-squares).

I.e. try

(display (list-of-squares))

--=20
Jens Axel S=F8gaard



Report this thread to moderator Post Follow-up to this message
Old Post
Jens Axel Søgaard
04-10-05 09:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Scheme archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:06 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.