a couple of beginner's questions

2 views
Skip to first unread message

Michele Simionato

unread,
Oct 23, 2003, 1:59:50 AM10/23/03
to
Since I have got such helpful replies with my previous posts, here I
insist with two other questions ;) I am sure these are simple questions,
but I haven't found the answer in the documentation I have looked at.
BTW, where are Scheme FAQs ? I would appreciate suggestions about
Scheme resources (I have already DrScheme, SICP and few other references).

----

Question 1: functions with a variable nummber of arguments.

Suppose I define the following trivial function:

(define f
(lambda (first . rest)
(display first) (display rest)))

It works: (f 1 2 3) displays (1 (2 3)), as expected.
Now, I want to call f from a function g with a variable number of
arguments; If I do it the simple way

(define g
(lambda (first . rest)
(f first rest)))

then (g 1 2 3) returns 1((2 3)) whereas I would like to get
1 (2 3). The syntax

(define g
(lambda (first rest)
(f first rest)))

would do the job, but I want to call g with a variable number of arguments,
just as f, now with two arguments. IOW, is there an easy way of splicing the
list "rest" ? I would imagine something so simple can be done without using
macros, isnt'it ?

Question 2: how mutable are Scheme lists?

As a learning exercise, I am trying to convert a Python script to
Scheme; essentially, I want to remove elements from sublists of a list.
In Python I can do something like this:

>>> lls=[ [1], [2,3] ] # a list of lists
>>> for ls in lls: # for each sublist, remove the first element ...
... if ls[0]==2: del ls[0] # ... if it is equal to 2
...
>>> lls
[[1], [3]]

How would translate this to Scheme? I don't see a del-like instruction,
should I build a new list ?

TIA,


Michele

Anton van Straaten

unread,
Oct 23, 2003, 3:13:41 AM10/23/03
to
Michele Simionato wrote:
> BTW, where are Scheme FAQs ? I would appreciate suggestions about
> Scheme resources (I have already DrScheme, SICP and few other references).

Try googling for "Scheme FAQ". And check out schemers.org.

> Question 1: functions with a variable nummber of arguments.
>
> Suppose I define the following trivial function:
>
> (define f
> (lambda (first . rest)
> (display first) (display rest)))
>
> It works: (f 1 2 3) displays (1 (2 3)), as expected.
> Now, I want to call f from a function g with a variable number of
> arguments; If I do it the simple way
>
> (define g
> (lambda (first . rest)
> (f first rest)))
>
> then (g 1 2 3) returns 1((2 3)) whereas I would like to get
> 1 (2 3). The syntax
>
> (define g
> (lambda (first rest)
> (f first rest)))
>
> would do the job, but I want to call g with a variable number of
arguments,
> just as f, now with two arguments. IOW, is there an easy way of splicing
the
> list "rest" ? I would imagine something so simple can be done without
using
> macros, isnt'it ?

Yes. Use (apply f first rest).

> Question 2: how mutable are Scheme lists?

Very. Take a look at set-car! and set-cdr!. Example of deleting an element
of a list:

(define lis (list 1 2 3 4))
(set-cdr! (cdr lis) (cdddr lis))

...deletes the third element of the list. Generalizing this to a "delete
specified element" function might be a nice exercise.

Anton

L.J. Buitinck

unread,
Oct 23, 2003, 6:19:11 AM10/23/03
to
Michele Simionato wrote:
> Since I have got such helpful replies with my previous posts, here I
> insist with two other questions ;) I am sure these are simple questions,
> but I haven't found the answer in the documentation I have looked at.
> BTW, where are Scheme FAQs ? I would appreciate suggestions about
> Scheme resources (I have already DrScheme, SICP and few other references).

not FAQs, but generally useful are:
_The Scheme Programming Language_, http://www.scheme.com/tspl2d
http://www.readscheme.org

--
Segui il tuo corso, e lascia dir le genti.

Lars

Bruce Lewis

unread,
Oct 23, 2003, 9:42:57 AM10/23/03
to
mi...@pitt.edu (Michele Simionato) writes:

> (define g
> (lambda (first . rest)
> (f first rest)))
>
> then (g 1 2 3) returns 1((2 3)) whereas I would like to get
> 1 (2 3).

(define g
(lambda args
(apply f args)))

Michele Simionato

unread,
Oct 24, 2003, 3:16:55 AM10/24/03
to
"Anton van Straaten" <an...@appsolutions.com> wrote in message news:<FcLlb.14103$W16....@newsread2.news.atl.earthlink.net>...

> Take a look at set-car! and set-cdr!. Example of deleting an element
> of a list:
>
> (define lis (list 1 2 3 4))
> (set-cdr! (cdr lis) (cdddr lis))
>
> ...deletes the third element of the list. Generalizing this to a "delete
> specified element" function might be a nice exercise.
>
> Anton


Uhmm...

sorry, but I don't see the point of such complication for such
a trivial task. I mean, I see how does it work, and it is
marginally interesting to know how lists are managed internally,
but I don't see why I must descend to this level of detail for
such a trivial job.

IOW: once I have understood that Scheme lists
are recursively built as russian dolls, why I must open all
the dolls one by one by hand? The machine should do it for me!

I mean, there should be a standard library to implement this
kind of things. Internals should be hidden, unless you are
doing something really sophisticated or you are teaching CS to bad
students and you need to raise the barrier for selection purposes ;)

Most of people have a job to do and they want the job done, not to
spend time implementing such details. Clearly, this discourage a
lot of people from using Scheme. I myself would not use Scheme if
I had a real job to do, with dead-lines to respect, and I was forced
to spend my time reinventing the wheel, especially when there are
alternative languages that don't require me to think. Notice that
"not to think" is a good thing: I should not to think to the easy
things, in such a way to be free to think to more important issues.

Now, I am learning Scheme only for the sake of learning, so my aim
is exactly to reinvent the wheel: nevertheless, it is clear that most
people cannot have the time for this. So, Scheme cannot be largely used
outside academia; probably it could be used more if it had a
very large standard library. But this is beside the point.

The point is that I don't need all that complication in order to
solve my problem, it is much simpler to create a new list:

> (map (lambda (ls) (if (= (car ls) 2) (cdr ls) ls)) '((1) (2 3)))
((1) (3))

Notice that I only need to remove the 0-th element.
For sake of esperiment, I wrote a 'remove' function removing the
n-th element of a list and creating a new list:

(define (remove ls n)
(if (= n 0) (cdr ls)
(append (list (car ls)) (remove (cdr ls) (- n 1)))))

This works, but I wonder if there is a better way or if this
is considered good Scheme.

BTW, I also do not understand how ``append!`` works. Why

> (define ls '(1 2))
> (append! ls '(3))
(1 2 3)
> ls
(1 2 3)

works as I expect whereas

> (define ls ())
> (append! ls '(3))
(3)
> ls
()

does not give (3) ??? What's the logic here?


Michele

Sampo Smolander

unread,
Oct 24, 2003, 4:15:42 AM10/24/03
to
Michele Simionato <mi...@pitt.edu> wrote:
>> (define ls '(1 2))
>> (append! ls '(3))
> (1 2 3)
>> ls
> (1 2 3)

> works as I expect whereas

>> (define ls ())
>> (append! ls '(3))
> (3)
>> ls
> ()

> does not give (3) ??? What's the logic here?

That's funny.

I just make a guess, and hope someone corrects me it I get this wrong.

When you (define ls '(1 2)), the symbol ls gets to point to a newly
reserved piece of memory, that contains '(1 2). Then the mutating
append! can come, and mutate the content of memory.

But when you (define ls '()), you actually just put the symbol
ls to point to, well to whatever is your scheme system's way to
internally present the empty list. And this is something
that you just cannot mutate.

Jens Axel Søgaard

unread,
Oct 24, 2003, 7:13:32 AM10/24/03
to
Michele Simionato wrote:
> "Anton van Straaten" wrote
>
>>Take a look at set-car! and set-cdr!. Example of deleting an element
>>of a list:
>>
>>(define lis (list 1 2 3 4))
>>(set-cdr! (cdr lis) (cdddr lis))
>>
>>...deletes the third element of the list. Generalizing this to a "delete
>>specified element" function might be a nice exercise.

...

> Now, I am learning Scheme only for the sake of learning, so my aim
> is exactly to reinvent the wheel: nevertheless, it is clear that most
> people cannot have the time for this. So, Scheme cannot be largely used
> outside academia; probably it could be used more if it had a
> very large standard library. But this is beside the point.

You forgot that Anton knows you are a beginner and therefore gave
the answer that a beginner will profit the most from.

The most comprehensive list library I have seen (for any language)
is Olin Shivers:

<http://srfi.schemers.org/srfi-1/srfi-1.html>

--
Jens Axel Søgaard

L.J. Buitinck

unread,
Oct 24, 2003, 8:06:25 AM10/24/03
to
Sampo Smolander wrote:
> When you (define ls '(1 2)), the symbol ls gets to point to a newly
> reserved piece of memory, that contains '(1 2). Then the mutating
> append! can come, and mutate the content of memory.
>
> But when you (define ls '()), you actually just put the symbol
> ls to point to, well to whatever is your scheme system's way to
> internally present the empty list. And this is something
> that you just cannot mutate.

the logic is: APPEND! changes the CDR of the last pair of its first arg
to the value of its second arg.

a definition of APPEND! (from the top of my head):

(define (append! x y)
(if (null? (cdr x))
(set-cdr! x y)))

note that appending to () would signal an error in this version.
the point: () doesn't have a CDR. it's not even a pair.

Anton van Straaten

unread,
Oct 24, 2003, 11:48:39 AM10/24/03
to
Michele Simionato wrote:
> sorry, but I don't see the point of such complication for such
> a trivial task. I mean, I see how does it work, and it is
> marginally interesting to know how lists are managed internally,

In Scheme or Lisp, this is of more than marginal interest - it's essential
knowledge.

> Most of people have a job to do and they want the job done, not to
> spend time implementing such details. Clearly, this discourage a
> lot of people from using Scheme. I myself would not use Scheme if
> I had a real job to do, with dead-lines to respect, and I was forced
> to spend my time reinventing the wheel, especially when there are
> alternative languages that don't require me to think.

"Alternative languages that don't require me to think" is a nice summary of
the problem with software development! Happily, Scheme requires you to
think, as does the solution to any worthwhile problem:

> Notice that "not to think" is a good thing: I should not to think to the
> easy things, in such a way to be free to think to more important issues.

Are you sure you know the difference between the easy and important issues,
when you're learning a new language? Are you sure the word "list" means the
same thing in Scheme that it does in languages you're already familiar with?
In particular, the word "list" in Python means something entirely different.

> Now, I am learning Scheme only for the sake of learning,
> so my aim is exactly to reinvent the wheel

So what are you complaining about?

> The point is that I don't need all that complication in order to
> solve my problem, it is much simpler to create a new list:
>
> > (map (lambda (ls) (if (= (car ls) 2) (cdr ls) ls)) '((1) (2 3)))
> ((1) (3))

Creating a new list is perfectly reasonable, but you asked for a "del-like
instruction".

> For sake of esperiment, I wrote a 'remove' function removing the
> n-th element of a list and creating a new list:
>
> (define (remove ls n)
> (if (= n 0) (cdr ls)
> (append (list (car ls)) (remove (cdr ls) (- n 1)))))

That's very close to a good solution. Instead of 'append', though, try
using 'cons', which is more appropriate and efficient here.

> This works, but I wonder if there is a better way or if this
> is considered good Scheme.
>
> BTW, I also do not understand how ``append!`` works. Why
>
> > (define ls '(1 2))
> > (append! ls '(3))
> (1 2 3)
> > ls
> (1 2 3)
>
> works as I expect whereas
>
> > (define ls ())
> > (append! ls '(3))
> (3)
> > ls
> ()
>
> does not give (3) ??? What's the logic here?

The name append! is misleading. Think of it as append!-if-not-empty. To
understand it, implement a function 'last-pair' which returns the last pair
of a list. Then append! is defined as (set-cdr! (last-pair lis)). What's
the last pair of '()?

I recommend reading www.htdp.org . It may appear too simple at first for an
experienced programmer, but skim parts of it if you have to. It covers some
important core concepts, which ultimately will explain things like why you
need "to know how lists are managed internally".

I also second Jens' recommendation of srfi-1 as a list library. However,
while you're learning Scheme, you'd do better to work at a lower level.

Anton

David Rush

unread,
Oct 24, 2003, 5:07:14 PM10/24/03
to
On 24 Oct 2003 00:16:55 -0700, Michele Simionato <mi...@pitt.edu> wrote:
> sorry, but I don't see the point of such complication for such
> a trivial task. I mean, I see how does it work, and it is
> marginally interesting to know how lists are managed internally, but I
> don't see why I must descend to this level of detail for
> such a trivial job.

Others have already pointed you at SRFI-1, so I won't bother.

But there's a more important reason why you should get comfy with the
detail:

Recursive Structures

functional languages like Scheme make more use of these than any other
language family. In particular Scheme has no looping control structures,
only recursion. This is a good thing because there ends up being a lot
of symmetry between your function and data-structure defintiions.

Lists are just the most trivial example of a recursive data structure.
Yes, SRFI-1 implements all kinds of combinators which can make you life
easier, but it is frequently the case that,once you're comfortable with
lots of recursion that you can make much faster programs by fusing
multiple passes over a list (or other structure) into a single recursive
pass that calculates several things in parallel.

And I'll admit that it's a bit out of fashion to worry about performance
these days, but I've been seeing a move into very CPU intensive data
analysis and I strongly suspect that we'll soon being seeing some of
these applications being deployed on the million-user scale. The chip-heads
won't be able to bail us software guys out forever.

david rush
--
(\x.(x x) \x.(x x)) -> (s i i (s i i))
-- aki helin (on comp.lang.scheme)

Michele Simionato

unread,
Oct 25, 2003, 2:51:39 AM10/25/03
to
"Anton van Straaten" <an...@appsolutions.com> wrote in message news:<rRbmb.339$X22...@newsread2.news.atl.earthlink.net>...

> Michele Simionato wrote:
> > Most of people have a job to do and they want the job done, not to
> > spend time implementing such details. Clearly, this discourage a
> > lot of people from using Scheme. I myself would not use Scheme if
> > I had a real job to do, with dead-lines to respect, and I was forced
> > to spend my time reinventing the wheel, especially when there are
> > alternative languages that don't require me to think.
> "Alternative languages that don't require me to think" is a nice summary of
> the problem with software development! Happily, Scheme requires you to
> think, as does the solution to any worthwhile problem:

I wrote the sentence "alternative languages that don't require me to
think"
on purpose. Assume I am a biophysicist working on a cure for genetic
diseases;
I must spend a part of my time programming. I want this part to be as
small
as possible: I will not choose a language that forces myself to
devolve my
precious time to think about how to implement "remove the n-th element
from a list".
I claim this is not a worthwhile problem for the genetist.
On the other hand, assume I am a computer scientist: they I already
know the
algorithm for removing the n-th element from a list. What's the point
to be
forced to write it again? This is not a worthwhile problem even for
the
computer scientist.
The only person for which solving the exercise is a worthwhile problem
is the
freshman in a CS department (not even in other departments).
Now, I am not a freshman in a CS department, so I expected an answer
such as
"look at that library; if you want to know how does it work, here is
an example with set-car! and set-cdr!". But I had no information at
all on the existence of
the library, so I assumed there was no standard library for that and I
got
a bad (and false) impression about Scheme.

> > Notice that "not to think" is a good thing: I should not to think to the
> > easy things, in such a way to be free to think to more important issues.
> Are you sure you know the difference between the easy and important issues,
> when you're learning a new language?

No, I am not sure. Probably I would think that "removing the n-th
element" is
not important and discover later that it was important. That would be
a fault,
but it would be *my* fault. You are not my mother.

> Are you sure the word "list" means the
> same thing in Scheme that it does in languages you're already familiar with?
> In particular, the word "list" in Python means something entirely different.

Yes, and actually I strongly dislike Python choice of calling "list"
what should
be called "array". BTW, Ruby got it right.

> > Now, I am learning Scheme only for the sake of learning,
> > so my aim is exactly to reinvent the wheel
> So what are you complaining about?

You do think that learning "how to remove the n-th element from a
list" is
important. Fine. Most probably you are right. However, you did not
give me
any choice. You could have said "there is the easy way (look at the
library)
and the true way (do it yourself), please choose as I wish". Maybe I
would
have chosen the wrong way but it was *my* choice, not yours.

> > For sake of esperiment, I wrote a 'remove' function removing the
> > n-th element of a list and creating a new list:
> >
> > (define (remove ls n)
> > (if (= n 0) (cdr ls)
> > (append (list (car ls)) (remove (cdr ls) (- n 1)))))
> That's very close to a good solution. Instead of 'append', though, try
> using 'cons', which is more appropriate and efficient here.

Damn, I had 'cons' on the point of my fingers, but that damned
'append'
conspired against me ...

> >
> > BTW, I also do not understand how ``append!`` works. Why
> >
> > > (define ls '(1 2))
> > > (append! ls '(3)) (1 2 3)
> > > ls
> > (1 2 3)
> >
> > works as I expect whereas
> >
> > > (define ls ())
> > > (append! ls '(3)) (3)
> > > ls
> > ()
> >
> > does not give (3) ??? What's the logic here?
> The name append! is misleading. Think of it as append!-if-not-empty. To
> understand it, implement a function 'last-pair' which returns the last pair
> of a list. Then append! is defined as (set-cdr! (last-pair lis)). What's
> the last pair of '()?

Then it should raise an error. Instead it returns (3) but does not
modify
the list. A sure recipe for bugs. What's the rationale for this
behavior?

> I recommend reading www.htdp.org . It may appear too simple at first for an
> experienced programmer, but skim parts of it if you have to. It covers some
> important core concepts, which ultimately will explain things like why you
> need "to know how lists are managed internally".

Yeah, I have a tendence to skim over long books and try things myself,
but
I should read it. I will compense by looking at the source code of
srfi-1 ;)

> I also second Jens' recommendation of srfi-1 as a list library. However,
> while you're learning Scheme, you'd do better to work at a lower level.
> Anton

Could very well be. Please, don't take my remarks as anything
personal.
I thank you for your reply which was quite useful. It is simply that
I didn't like the way it was formulated, leaving me in the ignorance
of
the library and giving me a false impression about the language.
This kind of things may discourage newcomers.


Michele Simionato

Lauri Alanko

unread,
Oct 25, 2003, 3:58:14 AM10/25/03
to
In article <2259b0e2.03102...@posting.google.com>,

Michele Simionato <mi...@pitt.edu> wrote:
> > The name append! is misleading. Think of it as append!-if-not-empty. To
> > understand it, implement a function 'last-pair' which returns the last pair
> > of a list. Then append! is defined as (set-cdr! (last-pair lis)). What's
> > the last pair of '()?
>
> Then it should raise an error. Instead it returns (3) but does not
> modify
> the list. A sure recipe for bugs. What's the rationale for this
> behavior?

http://srfi.schemers.org/srfi-1/srfi-1.html#LinearUpdateProcedures


Lauri Alanko
l...@iki.fi

Anton van Straaten

unread,
Oct 25, 2003, 1:08:09 PM10/25/03
to
Michele Simionato wrote:
> I wrote the sentence "alternative languages that don't require me
> to think" on purpose. Assume I am a biophysicist working on a
> cure for genetic diseases; I must spend a part of my time programming.
> I want this part to be as small as possible: I will not choose a language
> that forces myself to devolve my precious time to think about how to
> implement "remove the n-th element from a list".

Such a person would be well-advised to begin his question by stating his
goals, rather than phrasing the question as you did: "As a learning
exercise, ..."

I responded to you based on your stated goal of a learning exercise.
Perhaps you forgot how you originally phrased the question?

> I thank you for your reply which was quite useful.
> It is simply that I didn't like the way it was formulated

I must not have received the memo about "how to formulate answers to Michele
Simionato's questions".

> leaving me in the ignorance of the library and giving
> me a false impression about the language.

You gave yourself a false impression about the language, by erroneous
extrapolation. As a remedy to this sort of error, I recommend spending more
time with things that *do* require you to think.

> This kind of things may discourage newcomers.

It may discourage newcomers with poor attitudes, which doesn't bother me a
bit. Instead of answering my original response with a rant, you could have
simply asked "isn't there a library routine to do this"?

With that out of the way, some responses of a more technical nature:

> > The name append! is misleading. Think of it as append!-if-not-empty.
> > To understand it, implement a function 'last-pair' which returns the
last
> > pair of a list. Then append! is defined as (set-cdr! (last-pair lis)).
> > What's the last pair of '()?
>
> Then it should raise an error. Instead it returns (3) but does not
> modify the list. A sure recipe for bugs. What's the rationale for this
> behavior?

My pseudocode definition was incomplete - I didn't code the "-if-not-empty"
part which I mentioned.

The most direct rationale is that the value '() is not mutable, so because
of the call-by-value nature of Scheme, 'append!' has no way to modify the
value passed to it.

Lauri Alanko pointed out the "Linear Updating" description in SRFI-1 as a
broader justification for this behavior. It's certainly something you need
to be careful about. For initial learning, I'd recommend staying away from
these sorts of procedures. Rather use the non-mutating versions like
'append'. More below:

> > I recommend reading www.htdp.org . It may appear too simple at first
for an
> > experienced programmer, but skim parts of it if you have to. It covers
some
> > important core concepts, which ultimately will explain things like why
you
> > need "to know how lists are managed internally".
>
> Yeah, I have a tendence to skim over long books and try things myself,
> but I should read it. I will compense by looking at the source code of
> srfi-1 ;)

Something which the srfi's source will not make obvious is the point about
recursive structures which David Rush mentioned, and the symmetry between
recursive function and data structure definitions. When you program in this
way, you'll find that functions like 'append!' aren't often necessary.
However, it's a programming style that is unfamiliar to most people with
experience of imperative languages. I think that learning purely by reading
code works better when you already understand the paradigm in which the code
is written.

Anton

chain...@hotmail.com

unread,
Oct 26, 2003, 4:26:02 AM10/26/03
to
mi...@pitt.edu (Michele Simionato) wrote in message

> This kind of things may discourage newcomers.

Hi:

There are a lot of bigots out there who embrace Scheme or Common Lisp
as their last thruth; admittedly there are trillions of this kind of
people in the Lisp community as opposed to the Scheme community which
has maybe zero of this type of guys; I think Schemer's are the
friendlier mankind.

The much I like your critical attitude the much I have to beg differ
with your last sentence. I am more or less the the guy which you
described as biophysicist, though, I am an ordinary physicist in the
field of atmospheric science.

I had used Python before I have started to use Bigloo. However, I find
it much easier to program in Scheme than in the bluff-language Python.
Admittedly, Python has a huge library on predefined functions, but it
gets often very confusing. Search comp.lang.python for all the Python
problems which they have to cope with in their life. I only mention
this, because everybody on comp.lang.python wants to make us believe
that Python is for the beginner and illiterate.

By the way: I have never used set-car! or something like this in my
life, though, I write Scheme code every day fory my PhD.

Only out of curiosity: which programming language in your personal
book in proper use today would you classify as the language which you
are after. I mean did your ever encounter a programming language or
environment where you believed this is exactly your programming
language due to the fact that exactly this programming language
behaves in every respect as you would expect it that it does.


Fensterbrett

Michele Simionato

unread,
Oct 26, 2003, 12:20:27 PM10/26/03
to
"Anton van Straaten" <an...@appsolutions.com> wrote in message news:<Z5ymb.3732$FI2...@newsread1.news.atl.earthlink.net>...

> With that out of the way

Yes, let it pass. You are not supposed to read my mind and give
me the answers I expect to get. Also, you have the right to give me the
answer you prefer, not the answer I would like. After all, you are giving
your time to me for free.

I realize that: but, please, let me the right to point out to the newsgroup
if I feel that some reply is somewhat incomplete or misleading. I wrote my
remark for the sake of others like me: if I was mislead, others
could have been. Also, let me the possibility of expressing a little
rant if I get the impression that some information is hidden from me (in this
case the existence of the library). But let it pass, as I said.

> The most direct rationale is that the value '() is not mutable, so because
> of the call-by-value nature of Scheme, 'append!' has no way to modify the
> value passed to it.

Yes, but I would expect to get an error when I try to mutate something which
is not mutable, this was my point. I expect there is a rationale for not
raising an error too.

> Lauri Alanko pointed out the "Linear Updating" description in SRFI-1 as a
> broader justification for this behavior. It's certainly something you need
> to be careful about. For initial learning, I'd recommend staying away from
> these sorts of procedures. Rather use the non-mutating versions like
> 'append'.

Yeah, I will do this way.

> I recommend spending more time with things that *do* require you to think.

Don't worry, I have plenty of such things.


Michele

Michele Simionato

unread,
Oct 26, 2003, 12:33:53 PM10/26/03
to
chain...@hotmail.com wrote in message news:<f7afbb21.03102...@posting.google.com>...

> There are a lot of bigots out there who embrace Scheme or Common Lisp
> as their last thruth; admittedly there are trillions of this kind of
> people in the Lisp community as opposed to the Scheme community which
> has maybe zero of this type of guys; I think Schemer's are the
> friendlier mankind.

Yes, I have got useful and friendly replies. Maybe I have annoyed a bit Anton
but still he answered to my questions, so he was helpful. I have no complaints
at all versus the newsgroup, nor versus Anton, he has the right to
get a bit annoyed sometimes (me too I have that right, BTW).

> The much I like your critical attitude the much I have to beg differ
> with your last sentence. I am more or less the the guy which you
> described as biophysicist, though, I am an ordinary physicist in the
> field of atmospheric science.

As a matter of fact, I am a physicists too, or at least I was one till
a couple of months ago. I was in theoretical Physics, anyway.

> I had used Python before I have started to use Bigloo. However, I find
> it much easier to program in Scheme than in the bluff-language Python.
> Admittedly, Python has a huge library on predefined functions, but it
> gets often very confusing. Search comp.lang.python for all the Python
> problems which they have to cope with in their life. I only mention
> this, because everybody on comp.lang.python wants to make us believe
> that Python is for the beginner and illiterate.

I haven't had any problem with Python, but different peple have different
experiences, so this is not strange.

> Only out of curiosity: which programming language in your personal
> book in proper use today would you classify as the language which you
> are after. I mean did your ever encounter a programming language or
> environment where you believed this is exactly your programming
> language due to the fact that exactly this programming language
> behaves in every respect as you would expect it that it does.

That's a very delicate question. I felt exactly the way you describe
when I first learned Python. But it depends a lot on the experience you have.
If you only have experience with toy languages (my background was Basic
and Pascal) you get a revelation when you find a better language.
But if you already know a decent language your expectations becomes
much higher and it becomes more difficult to get satisfied with a new language.
I guess that a really experienced programmer would think that no language
is "the" language. There could be a language which is better than another
for a given task, but there is no language which is perfect. I do think
that Python is a good language for the scope of its applications,
but it is a humble language and does not pretend to have everything.
So, the developers decided not to put macros, continuations or other
stuff like that. Now, I want to learn about all this stuff, and
therefore I must learn a language which supports it.
Common Lisp is big and does not satisfy my sense of aestetics,
so I have chosen Scheme. I thinks this is not surprising.

A final word: my critical posts should not be interpreted as rants
against Scheme, but as requests for explanations about things that
surprises me or that are unclear to me. I have got the habit of
asking when I don't understand something.

> Fensterbrett

Michele

Matthias Felleisen

unread,
Oct 26, 2003, 12:44:51 PM10/26/03
to

Michele Simionato wrote:
> I guess that a really experienced programmer would think that no language
> is "the" language.

I always tell me students that Scheme is my second favorite programming
language. After they recover from this statement, they naturally always
ask what my favorite language is, to which I respond with "I am still
working on it." That is, really experience programmers always try to
improve on their major mode of thought. -- Matthias

Marcin 'Qrczak' Kowalczyk

unread,
Oct 26, 2003, 1:46:38 PM10/26/03
to
On Sun, 26 Oct 2003 09:20:27 -0800, Michele Simionato wrote:

> Yes, but I would expect to get an error when I try to mutate something which
> is not mutable, this was my point. I expect there is a rationale for not
> raising an error too.

append! doesn't mean "mutate the first argument to have other arguments
appended". It means "return the concatenation of arguments, maybe mutating
them, maybe not - you are not supposed to look at the argument afterwards,
only at the result".

--
__("< Marcin Kowalczyk
\__/ qrc...@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/

Michele Simionato

unread,
Oct 27, 2003, 1:24:37 AM10/27/03
to
Marcin 'Qrczak' Kowalczyk <qrc...@knm.org.pl> wrote in message news:<pan.2003.10.26....@knm.org.pl>...

> On Sun, 26 Oct 2003 09:20:27 -0800, Michele Simionato wrote:
>
> > Yes, but I would expect to get an error when I try to mutate something which
> > is not mutable, this was my point. I expect there is a rationale for not
> > raising an error too.
>
> append! doesn't mean "mutate the first argument to have other arguments
> appended". It means "return the concatenation of arguments, maybe mutating
> them, maybe not - you are not supposed to look at the argument afterwards,
> only at the result".

I think I have got it now. When I see a bang I should interpret it as

"attention, here the implementation, for sake of efficiency, is free to
have side effects, so be prepared and don't rely on the argument
aftwerwards"

In this case everything makes sense, no problem at all.
I really missed the point before and I expected the bang to mean

"here there will certainly be side effects, so you can rely on them"

Quite a different interpretation, indeed. Essentially, you are saying
that side effects are always bad in Scheme, they are only tolerate
sometimes, but I should never rely on them.

That's good. Actually, I like this way.


Michele

Lauri Alanko

unread,
Oct 27, 2003, 2:26:55 AM10/27/03
to
mi...@pitt.edu (Michele Simionato) virkkoi:

> I think I have got it now. When I see a bang I should interpret it as
>
> "attention, here the implementation, for sake of efficiency, is free to
> have side effects, so be prepared and don't rely on the argument
> aftwerwards"

Sorry, but that's not the final answer either. For the "linear-update"
procedures this is the convention, but other times the presence of a
bang means, as you say,

> "here there will certainly be side effects, so you can rely on them"

This is the case for set!, set-car!, vector-set!, string-set!, and
often also mutators for many other datatypes that the implementation may
provide. These operations are designed to support reliable imperative
side effects.

How do you know, when the bang means what? In the end, only by reading
the docs. Sorry. But as a rule of thumb, if the operation works on a
fairly simple and straightforward data structure and has an
"unspecified" return value, it is meant for primitive reliable side
effects. If it works on more complex compound structures (such as lists)
and returns a meaningful value, the linear-update condition is probably
meant.

True, it's not a very coherent convention.


Lauri Alanko
l...@iki.fi

Anton van Straaten

unread,
Oct 27, 2003, 2:30:30 AM10/27/03
to
Michele Simionato wrote:
> Marcin 'Qrczak' Kowalczyk <qrc...@knm.org.pl> wrote
> > On Sun, 26 Oct 2003 09:20:27 -0800, Michele Simionato wrote:
> >
> > > Yes, but I would expect to get an error when I try to mutate something
which
> > > is not mutable, this was my point. I expect there is a rationale for
not
> > > raising an error too.
> >
> > append! doesn't mean "mutate the first argument to have other arguments
> > appended". It means "return the concatenation of arguments, maybe
mutating
> > them, maybe not - you are not supposed to look at the argument
afterwards,
> > only at the result".
>
> I think I have got it now. When I see a bang I should interpret it as
>
> "attention, here the implementation, for sake of efficiency, is free to
> have side effects, so be prepared and don't rely on the argument
> aftwerwards"

Careful - that's not a general rule, it applies only to the "linear update"
procedures in SRFI-1 and any other procedures which are identified as having
similar behavior.

> In this case everything makes sense, no problem at all.
> I really missed the point before and I expected the bang to mean
>
> "here there will certainly be side effects, so you can rely on them"

This is the usual meaning of a bang in Scheme - certainly all the procedures
in R5RS with bangs in their name have guaranteed mutating behavior. I think
it might have been a good idea for SRFI-1 to have picked some other
indicator for the linear update procedures.

Anton

chain...@hotmail.com

unread,
Oct 27, 2003, 2:56:28 AM10/27/03
to
mi...@pitt.edu (Michele Simionato) wrote in message

> A final word: my critical posts should not be interpreted as rants

> against Scheme, but as requests for explanations about things that
> surprises me or that are unclear to me. I have got the habit of
> asking when I don't understand something.

You are welcome. You may not forget that Anton v. S has a very deep
knowledge of Scheme. The latter is essential to seperating meanings in
a discussion because for example my knowledge of Scheme is very
shallow and I will always let you go.

However, I can give you the advice: ask, ask and ask but at the same
time listen, listen and listen. For example at the beginning of my
Scheme career I had great problems to use list's set-append properly.
It is/was very counter-intuitive to me, but I got the advice to use a
construct like the following:

(set! result (cons (.....) result))

and upon the exit point I have to reverse the list: (reverse result).

This is my favorite construct now to handle lists; often I do only use
"cons" without the set!. I have never used set-append in the
following. As a side note, consing is very effective under Bigloo.

I think there are often a great many of ways in order to complete a
task.

Regards,
Fensterbrett
PS: Do the following experiment: go to comp.lang.lisp and ask
questions; as long as you are on their line you are treated friendly
but once you start to think and expressing your own opinion they will
burn you on stake.

Michele Simionato

unread,
Oct 27, 2003, 12:32:25 PM10/27/03
to
Lauri Alanko <l...@iki.fi> wrote in message news:<bnihbv$m0$1...@la.iki.fi>...

> mi...@pitt.edu (Michele Simionato) virkkoi:
> > I think I have got it now. When I see a bang I should interpret it as
> >
> > "attention, here the implementation, for sake of efficiency, is free to
> > have side effects, so be prepared and don't rely on the argument
> > aftwerwards"
>
> Sorry, but that's not the final answer either. For the "linear-update"
> procedures this is the convention, but other times the presence of a
> bang means, as you say,
>
> > "here there will certainly be side effects, so you can rely on them"
>
> This is the case for set!, set-car!, vector-set!, string-set!, and
> often also mutators for many other datatypes that the implementation may
> provide. These operations are designed to support reliable imperative
> side effects.

I realized that. I also realized that Scheme is not a monolitic
language.
It has a long history, many implementations, and there is no such a
thing as "the right, unique Scheme way". Different implementors may
have different ideas about even basic concepts such as "set!" and
"define".
This was really surprising for me at the beginning.
Now I am starting to see how does it work. Putting things in context,
the slight inconsistency in the notations of srfi-1 is understandable.
Quite interesting to see how different languages have different
philosophies.

Thanks to everybody for the help,


Michele

Reply all
Reply to author
Forward
0 new messages