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

Newbie: using 'first to mimic car in procedure.

Hi all, and thank you Pascal for the excellent response (below).

In your code you used something I have not seen before and I was hoping
someone might explain it to me.

Please excuse my ignorance here but I'm trying to understand certain parts
of your code (in context).

For example:
(let ((item (what 'first from-where)))

'let' I understand.  However, your use of 'first - no clue at all.

'first resolves to first - which is a symbol.  I know (yeah - sure :) that I
can't use your symbol first on a string but in the context of your code, it
seems that first referred to the first 'word' of the string sentence defined
using position (to first locate the start position of the word 0 as default
and end position - positions start from 0 to length of string -1).  Then
'rest which is the rest of the sentence as yet unprocessed.  Your 'first and
'rest are the equivalent of first and rest (car and cdr) for lists???

I've never seen this used in Scheme code as yet: 'first 'rest.  (Solution:
look at more code and annoy people politely :)

Would you mind explaining it to me?

I need to really look at what you did here ... just takes a bit to sink in
... so I understand what is happening and why you did what you did.  Such a
really nice solution.

Thanks again,


"Pascal Bourguignon" <p@informatimago.com> wrote in message



Pascal answered my post very well.  I don't want to annoy anyone with the
new thread so his response is below.

Thanks again, Pascal.

[... Pascal's Response ...]

Not at all.  Indeed, I went over the definition of the interface of
the function what somewhat quickly.

The point here is that when we write (collect what where), to be able
to work, the function collect needs to know several things from what;
it needs to know:

   - what is the first item?
   - what is the other items (the rest)?
   - when there is no remaining items?

There are several possibilities for a single function to return all
these answers.

I made the choice of adding a selector parameter to the 'what'
function.  For this selector, I used symbols first and rest. (At
first, I had an additionnal selector empty?, but I eventually merged
it with first, which now returns a list of 0 or 1 item, 0 when the
sentence is empty, when there remains no items).

The model here is that of objects receiving messages, the symbol first
and rest being the message sent to the 'what' object, with the where

But we could do it all at once:

  (define (what sentence)
     (if remains-item?

and we'd then write collect as:

(define (collect what where)
   (let ((step (what where)))
      (if (first step)
          (cons (second step) (what (third step)))

Which indeed gives a simplier solution, and avoids some duplication in
the what functions.

__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc