Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SCM and SLIB

15 views
Skip to first unread message

blm...@myrealbox.com

unread,
Dec 14, 2009, 3:48:56 AM12/14/09
to

Lately I've been trying to teach myself a little Scheme, which
has been a lot of fun though rather humbling (I've been writing
code in various languages for a long time, but had never made a
very serious effort to learn a functional language, and it's --
different, all right). Some things I've tried lately, though, seem
to be running aground in a way that makes me suspect installation
problems .... :

For reasons I no longer remember clearly I chose to try the SCM
implementation, but it seems not to work very well with some
things in SLIB -- for example, I haven't been able to make either
syntax-case or structure work. For example, trying to run the code

(require 'structure)
(define-structure point x y color)

produces the error message

;ERROR: "temp.scm": unbound variable: define-structure

while trying to run the code

(require 'syntax-case)
(define-syntax my-or
(lambda (x)
(syntax-case x ()
((_) (syntax #f))
((_ e) (syntax e))
((_ e1 e2 e3 ...)
(syntax (let ((t e1)) (if t t (my-or e2 e3 ...))))))))

(copied from an example found online) gives the error messages
(using "\" to split long lines)

;ERROR: "temp.scm": defsyntax: bad expression \
(#@lambda (x) (syntax-case x () ((_) (syntax #f)) ((_ e ...
; in expression: (#@lambda (x) (syntax-case x () ((_) (syntax #f)) \
((_ e ...
; in top level environment.
; defined by load: "temp.scm"


Both SCM and SLIB were installed from source, using .zip files
found at http://people.csail.mit.edu/jaffer/SCM. Many things
work, which makes me think the installation isn't hopelessly
broken, but maybe it's somewhere between "hopelessly broken" and
"completely functional"?

Am I doing something obviously wrong? Help appreciated!

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.

blm...@myrealbox.com

unread,
Dec 22, 2009, 7:46:20 AM12/22/09
to
In article <7omcfoF...@mid.individual.net>,
blm...@myrealbox.com <blm...@myrealbox.com> wrote:

[ snip ]

> For reasons I no longer remember clearly I chose to try the SCM
> implementation, but it seems not to work very well with some
> things in SLIB -- for example, I haven't been able to make either
> syntax-case or structure work.

[ snip ]

> Both SCM and SLIB were installed from source, using .zip files
> found at http://people.csail.mit.edu/jaffer/SCM. Many things
> work, which makes me think the installation isn't hopelessly
> broken, but maybe it's somewhere between "hopelessly broken" and
> "completely functional"?
>
> Am I doing something obviously wrong? Help appreciated!

I'm still mildly curious about why SCM and SLIB don't seem to
work well together -- I mean, aren't they by the same author? --
but it's not a matter of pressing concern any more; I'm trying
Guile now, which seems to natively support the things from SLIB
I was most interested in (syntax-case). *It* apparently doesn't
always work well with SLIB either -- for example,

(require? 'primes)

produces an error message apparently caused by SLIB and Guile
having different ideas about how many arguments list->array
takes -- and there are things about its support for the readline
library that i don't like as well as in SCM, but maybe it will
do to go on with.

For the record, maybe. I do rather wonder whether I'm somehow
pickier than the average new user, or making bad choices about
what implementation(s) to try, because I seem to be spending way
too much time wrestling with little glitches rather than getting
on with writing interesting programs. Comments welcome but not
required, maybe.

Aaron W. Hsu

unread,
Dec 22, 2009, 1:10:54 PM12/22/09
to
blm...@myrealbox.com <blm...@myrealbox.com> writes:

>Guile now, which seems to natively support the things from SLIB
>I was most interested in (syntax-case). *It* apparently doesn't
>always work well with SLIB either -- for example,

[...]

>For the record, maybe. I do rather wonder whether I'm somehow
>pickier than the average new user, or making bad choices about
>what implementation(s) to try, because I seem to be spending way
>too much time wrestling with little glitches rather than getting
>on with writing interesting programs. Comments welcome but not
>required, maybe.

IMO, if you are interested in playing with SYNTAX-CASE, then yes, you
may be choosing the wrong implementations. :-) I am sure that Guile and
SCM are perfectly workable (I have used SCM before, but it was less than glitch
free), but if you are interested in something like SYNTAX-CASE you might
want to actually look at one of the Schemes where SYNTAX-CASE
originated, or one of the recent production that were built with
SYNTAX-CASE in mind:

* (Petite) Chez Scheme:
Obviously I'd recommend this one, but it's a good choice if you want
to play with syntax-case. It is one of the Schemes that has had it
around for a very long time, and the implementation is quite stable.
A new 7.9.4 prerelease supporting R6RS is also out.
* PLT Scheme:
This one is also one of the Schemes that has had SYNTAX-CASE for
some time, and it may be one of the founding fathers as it were,
along with Chez Scheme. It's also a fairly mature Scheme, but IME,
not quite as stable.
* Ikarus, Ypsilon, IronScheme, &c.
These are all new kids on the block that started out as R6RS
implementations, which means that they support SYNTAX-CASE and
always have. Many of them are built on Aziz's version of psyntax.

Those would be my recommendations, probably in order, Chez, PLT, and
then Ikarus, if you want few glitches.

And if you are interested in writing interesting programs, and decide to
play with Petite Chez Scheme, you should check out my "Arctic
Repository" that contains lots of libraries for Chez Scheme, including
many ported libraries from other places.

Aaron W. Hsu
--
A professor is one who talks in someone else's sleep.

blm...@myrealbox.com

unread,
Dec 23, 2009, 11:11:42 AM12/23/09
to
In article <Wt-dnTaP__YzlqzW...@giganews.com>,

Thanks! I may take one or more of them for a spin .... I think
I started out with SCM because that's what some colleagues use;
I should ask them why they chose it. For Guile I don't quite
remember, but one of my criteria is that the program have nice
command-line tools, including support for command histories (think
"readline"). Probably I searched on Scheme and readline.

> And if you are interested in writing interesting programs, and decide to
> play with Petite Chez Scheme, you should check out my "Arctic
> Repository" that contains lots of libraries for Chez Scheme, including
> many ported libraries from other places.

First I'm hoping to get past the mental block caused by certain
functional-language terms ("lambda expression" and "closure" come
to mind). I think I might be making progress there ....

Aaron W. Hsu

unread,
Dec 23, 2009, 10:42:41 PM12/23/09
to
blm...@myrealbox.com <blm...@myrealbox.com> writes:

>Thanks! I may take one or more of them for a spin .... I think
>I started out with SCM because that's what some colleagues use;
>I should ask them why they chose it. For Guile I don't quite
>remember, but one of my criteria is that the program have nice
>command-line tools, including support for command histories (think
>"readline"). Probably I searched on Scheme and readline.

At the moment I can't recommend Guile to people. However, I am
optimistic that this will change in the future, as there is at least one
person I know of who is actively working to bring Guile around to the
status of a respectable Scheme implementation. I heartily encourage this
effort, and I like what I have seen so far.

>> And if you are interested in writing interesting programs, and decide to
>> play with Petite Chez Scheme, you should check out my "Arctic
>> Repository" that contains lots of libraries for Chez Scheme, including
>> many ported libraries from other places.

>First I'm hoping to get past the mental block caused by certain
>functional-language terms ("lambda expression" and "closure" come
>to mind). I think I might be making progress there ....

Well, if that's your mental block, maybe you shouldn't quite worry about
'syntax-case' yet. ;-)

Vadim_Z

unread,
Dec 24, 2009, 3:24:16 PM12/24/09
to
Hello,

On Dec 14, 11:48 am, blm...@myrealbox.com <blm...@myrealbox.com>
wrote:

> found athttp://people.csail.mit.edu/jaffer/SCM.  Many things


> work, which makes me think the installation isn't hopelessly
> broken, but maybe it's somewhere between "hopelessly broken" and
> "completely functional"?  
>
> Am I doing something obviously wrong?  Help appreciated!
>
> --
> B. L. Massingill
> ObDisclaimer:  I don't speak for my employers; they return the favor.


At first I'll answer to question about syntax-case.
As SLIB documentation states,
-----------cut----------------
In order to use syntax-case from an interactive top level, execute:

(require 'syntax-case)
(require 'repl)
(repl:top-level macro:eval)
-----------cut----------------
After that, in the inner syntax-case REPL, your syntax-case example
works. I think you should definitely consider reading SLIB
documentation about syntax-case.

Now, about define-structure. It works in SCM/SLIB. What is wrong is
the documentation about it.
There are two small problems with it. Firstly, define-structure should
be used in syntax-case REPL, as described above.
Secondly, there are a lot of different versions of define-structure.
The documentation in SLIB is related to the version in TSPL, while the
real implementation uses somewhat different syntax.

What you need is to type
(define-structure (point x y color))
and everything else works.

So, structure parameters should be passed as list. Also, the name of
setter is changed too -- one should use set-point-color!, not point-
color-set!. These changes can be seen from the 'structure.scm' source
file.

A little transcript follows:

----cut-----
vadim@rr-d:~$ scm
SCM version 5e5, Copyright (C) 1990-2006 Free Software Foundation.
SCM comes with ABSOLUTELY NO WARRANTY; for details type `(terms)'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `(terms)' for details.
;loading /usr/share/slib/require
;done loading /usr/share/slib/require.scm
;loading /usr/share/slib/require
;done loading /usr/share/slib/require.scm
;loading /usr/lib/scm/Link
;done loading /usr/lib/scm/Link.scm
;loading /usr/lib/scm/Transcen
;done loading /usr/lib/scm/Transcen.scm
> (require 'structure)
;loading /usr/share/slib/scainit
; loading /usr/share/slib/comlist
; done loading /usr/share/slib/comlist.scm
; loading /usr/share/slib/scaoutp
; done loading /usr/share/slib/scaoutp.scm
; loading /usr/share/slib/scaglob

;In file loaded from /usr/share/slib/scainit.scm:91:
;WARNING: "/usr/lib/scm/Iedline.scm": redefining built-in
identifier?
; done loading /usr/share/slib/scaglob.scm
; loading /usr/share/slib/scaexpp
; done loading /usr/share/slib/scaexpp.scm
;done loading /usr/share/slib/scainit.scm
#<unspecified>
> (require 'repl)
;loading /usr/share/slib/repl
;done loading /usr/share/slib/repl.scm
#<unspecified>
> (repl:top-level macro:eval)
> (define-structure (point x y color))
#<unspecified>
> (define p (make-point 3 5 'red))
#<unspecified>
> p
#(point 3 5 red)
> (point-x p)
3
> (point-color p)
red
> (set-point-color! p 'black)
#<unspecified>
> p
#(point 3 5 black)
----cut-----

So, SCM/SLIB is not as bad as it seems to be.

With best regards,
Vadim Zborovskii

Aaron W. Hsu

unread,
Dec 24, 2009, 5:50:36 PM12/24/09
to
Vadim_Z <vzbor...@gmail.com> writes:

>At first I'll answer to question about syntax-case.
>As SLIB documentation states,
>-----------cut----------------
>In order to use syntax-case from an interactive top level, execute:

>(require 'syntax-case)
>(require 'repl)
>(repl:top-level macro:eval)
>-----------cut----------------
>After that, in the inner syntax-case REPL, your syntax-case example
>works. I think you should definitely consider reading SLIB
>documentation about syntax-case.

Okay...yeah, I'm sorry, I just have to respond: EEEEWWWWW!

blm...@myrealbox.com

unread,
Jan 1, 2010, 2:31:09 PM1/1/10
to
In article <LsKdnZZnaaKsfq_W...@giganews.com>,

[ snip ]

> >> And if you are interested in writing interesting programs, and decide to
> >> play with Petite Chez Scheme, you should check out my "Arctic
> >> Repository" that contains lots of libraries for Chez Scheme, including
> >> many ported libraries from other places.
>
> >First I'm hoping to get past the mental block caused by certain
> >functional-language terms ("lambda expression" and "closure" come
> >to mind). I think I might be making progress there ....
>
> Well, if that's your mental block, maybe you shouldn't quite worry about
> 'syntax-case' yet. ;-)

Could be. :-) I'd probably be better served by reading introductory
books rather than just diving in and trying stuff, but the latter is
more my style for recreational programming, which is what this attempt
to learn Scheme is at this point.

Why I'm interested in syntax-case .... Eh, no, I don't think I want
to explain in detail, because I think there's a good chance that the
"problem" I hope syntax-case will help with is one I shouldn't be
trying to solve in the first place.

> --
> A professor is one who talks in someone else's sleep.

Great signature! and I speak as a former student and current
professor-of-sorts ....

blm...@myrealbox.com

unread,
Jan 1, 2010, 2:32:51 PM1/1/10
to
In article <ac43c0f9-8e2c-46ee...@m3g2000yqf.googlegroups.com>,

[ snip sig ]

> At first I'll answer to question about syntax-case.
> As SLIB documentation states,
> -----------cut----------------
> In order to use syntax-case from an interactive top level, execute:
>
> (require 'syntax-case)
> (require 'repl)
> (repl:top-level macro:eval)
> -----------cut----------------
> After that, in the inner syntax-case REPL, your syntax-case example
> works.

Hm! I remember looking at the lines above in the documentation,
and I *thought* I remembered trying them without success, but
apparently I'm misremembering, because ....

If I enter the above lines and then load my example file, it works
fine (prints/displays what it's supposed to). If I try just
putting the above lines at the start of the file to be loaded,
it loads without errors but doesn't print/display anything.
Probably I need to apply the advice in your next sentence to repl:

> I think you should definitely consider reading SLIB
> documentation about syntax-case.

Apparently so. I read as much as I had the time and patience and
background to understand, but I can believe that wasn't enough!

> Now, about define-structure. It works in SCM/SLIB. What is wrong is
> the documentation about it.
> There are two small problems with it. Firstly, define-structure should
> be used in syntax-case REPL, as described above.
> Secondly, there are a lot of different versions of define-structure.
> The documentation in SLIB is related to the version in TSPL, while the
> real implementation uses somewhat different syntax.
>
> What you need is to type
> (define-structure (point x y color))
> and everything else works.

Ah. Yes, so it does ....

> So, structure parameters should be passed as list. Also, the name of
> setter is changed too -- one should use set-point-color!, not point-
> color-set!. These changes can be seen from the 'structure.scm' source
> file.
>
> A little transcript follows:

[ example not quoted -- but appreciated ]

> So, SCM/SLIB is not as bad as it seems to be.

Just for the record -- my original question was meant to ask not
"why is SCM/SLIB broken?!" but "have I messed up the installation?
because this doesn't seem to be working, and I'm wondering whether
I'm doing something wrong." And apparently I *have* been doing
something wrong. Thanks for setting me straight!

blm...@myrealbox.com

unread,
Jan 20, 2010, 9:37:34 AM1/20/10
to
In article <7q70v2...@mid.individual.net>,

blm...@myrealbox.com <blm...@myrealbox.com> wrote:
> In article <ac43c0f9-8e2c-46ee...@m3g2000yqf.googlegroups.com>,
> Vadim_Z <vzbor...@gmail.com> wrote:
> > Hello,
> >
> > On Dec 14, 11:48 am, blm...@myrealbox.com <blm...@myrealbox.com>
> > wrote:
> > > Lately I've been trying to teach myself a little Scheme, which
> > > has been a lot of fun though rather humbling (I've been writing
> > > code in various languages for a long time, but had never made a
> > > very serious effort to learn a functional language, and it's --
> > > different, all right). Some things I've tried lately, though, seem
> > > to be running aground in a way that makes me suspect installation
> > > problems .... :
> > >
> > > For reasons I no longer remember clearly I chose to try the SCM
> > > implementation, but it seems not to work very well with some
> > > things in SLIB -- for example, I haven't been able to make either
> > > syntax-case or structure work.
> > >

[ snip ]

Following up a bit, rather belatedly ....

The documentation for syntax-case does indeed explain how to make
syntax-case work from an interactive top level -- with a caveat that
rather baffles me:

If the magic three lines above are loaded first/separately (either
explicitly or via ScmInit.scm), then if I load my syntax-case
example file, it executes and all is well.

If I try to just include them at the start of the file with the
example and load the whole file, then I get the same error as
before (";ERROR: "temp.scm": defsyntax: bad expression ....").

So I don't quite understand what's happening here, and reading
the documentation for repl:top-level was not very helpful --
"over my head" would be a pretty good description. :-)? :-(?
Maybe that can wait until I'm further into this "learn Scheme"
project, though.

But in any case .... I'd also like to be able to use syntax-case
in non-interactive mode, and while I've come up with something
that seems to mostly do what I want, maybe I've overlooked a
better solution? What I've tried:

If I try to add the magic three lines to the top of my example
and run it with the command "scm -f example-plus-init.scm",
again I get the error messages described earlier. If I put them
in ScmInit.scm, then "scm -f example.scm" gives the interactive
prompt -- and if I then press control-D (UNIX end of file), I get
the expected output and scm ends, which is better, I guess,
but not really what I had in mind. The best I've come up with so
far is

echo "(repl:quit)" | scm -f example.scm"

which pretty much does what I want, though it adds an interactive
prompt before the first line of output.

Is there a better way .... ?

(I guess it would be uncharitable or persnickety or something
to grumble about calling the initialization file ScmInit.scm and
insisting it be in $HOME if $HOME is defined -- I mean, a proper
UNIX initialization file should have a name starting in ".", right?
and/or there should be a way to override the default name? Sigh.)

[ snip ]

0 new messages