<div dir="ltr">Forgive me if I am super terribly wrong. Isn't it the case that an improper list is only known to be improper if we walk to the end and find something other than an empty? So wouldn't that mean "first" and "rest" take linear time since they must make sure the argument is a list? Clearly that doesn't happen. What am I missing?<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 7, 2014 at 10:16 AM, Daniel Carrera <span dir="ltr"><<a href="mailto:dcarrera@gmail.com" target="_blank">dcarrera@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok. That makes sense. A list is either '() or something plus a list.<div><br></div><div>Thanks.</div>
<div><br></div><div>Cheers,</div><div>Daniel.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On 7 March 2014 14:46, Jon Zeppieri <span dir="ltr"><<a href="mailto:zeppieri@gmail.com" target="_blank">zeppieri@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Oops, sorry about that empty message. I was going to say that your<br>
definition of a list is close, but it's missing something, A list is<br>
either:<br>
<br>
- the empty list; or<br>
- a pair, the second element of which is a list<br>
<br>
(cons 3 2) is a pair, and sometimes non-list pairs are called<br>
"improper lists," but they don't satisfy list?.<br>
<br>
<br>
On Fri, Mar 7, 2014 at 8:43 AM, Jon Zeppieri <<a href="mailto:zeppieri@gmail.com" target="_blank">zeppieri@gmail.com</a>> wrote:<br>
> On Fri, Mar 7, 2014 at 8:39 AM, Daniel Carrera <<a href="mailto:dcarrera@gmail.com" target="_blank">dcarrera@gmail.com</a>> wrote:<br>
>> What is (cons 3 2) ? What is the definition of a list? I thought that a list<br>
>> was defined as either '() or a pair.<br>
>><br>
>> Cheers,<br>
>> Daniel.<br>
>><br>
>><br>
>> On 7 March 2014 13:49, Jens Axel Søgaard <<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>> wrote:<br>
>>><br>
>>> The value (cons 3 42) is not a list. The function car will extract 3,<br>
>>> but first will fail.<br>
>>><br>
>>> /Jens Axel<br>
>>><br>
>>><br>
>>> 2014-03-07 13:40 GMT+01:00 Daniel Carrera <<a href="mailto:dcarrera@gmail.com" target="_blank">dcarrera@gmail.com</a>>:<br>
>>> > Thanks. That's a very useful tip (being able to get at the source code).<br>
>>> > I<br>
>>> > am a bit confused by the condition "(and (pair? x) (list? x))". It seems<br>
>>> > to<br>
>>> > me that this could just be replaced with "(pair? x)". The "list?"<br>
>>> > doesn't<br>
>>> > add anything. Am I wrong?<br>
>>> ><br>
>>> > Also, I don't see exactly how "first" and "car" behave different on a<br>
>>> > non-list. They both raise an error. The errors are just worded<br>
>>> > differently.<br>
>>> ><br>
>>> > On the same file, I found the definition of empty?<br>
>>> ><br>
>>> > (define empty? (lambda (l) (null? l)))<br>
>>> ><br>
>>> > Wouldn't it be more economical to write "(define empty? null?)" and<br>
>>> > allow<br>
>>> > them to be synonyms?<br>
>>> ><br>
>>> > Cheers,<br>
>>> > Daniel.<br>
>>> ><br>
>>> ><br>
>>> > On 7 March 2014 12:16, Jens Axel Søgaard <<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>> wrote:<br>
>>> >><br>
>>> >> For lists first/rest works the same as car/cdr.<br>
>>> >> For non-lists there is a difference: first and rest signals an error.<br>
>>> >> The names first and rest makes it easier for a human reader of<br>
>>> >> a piece of code to see that the program works on lists only.<br>
>>> >><br>
>>> >> For the curious, the definition of first is:<br>
>>> >><br>
>>> >> (define (first x)<br>
>>> >> (if (and (pair? x) (list? x))<br>
>>> >> (car x)<br>
>>> >> (raise-argument-error 'first "(and/c list? (not/c empty?))" x)))<br>
>>> >><br>
>>> >> I found this definition like this:<br>
>>> >> 1. Entered this program in DrRacket:<br>
>>> >> #lang racket<br>
>>> >> first<br>
>>> >> 2. Clicked the "Check Syntax" button<br>
>>> >> 3. Right clicked the identifier first and chose "Open defining file"<br>
>>> >> 4. Chose "first" in the definition-drop-down in the upper left corner.<br>
>>> >><br>
>>> >> /Jens Axel<br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >> 2014-03-07 11:45 GMT+01:00 Daniel Carrera <<a href="mailto:dcarrera@gmail.com" target="_blank">dcarrera@gmail.com</a>>:<br>
>>> >> > Hello,<br>
>>> >> ><br>
>>> >> > Is there any difference between `first` and `car`, or between `last`<br>
>>> >> > and<br>
>>> >> > `cdr`, or between `empty? and null?` ?<br>
>>> >> ><br>
>>> >> > I had assumed that these were just synonyms, added by Racket because<br>
>>> >> > they<br>
>>> >> > might be more memorable to a student. But apparently Racket doesn't<br>
>>> >> > think<br>
>>> >> > they are equal:<br>
>>> >> ><br>
>>> >> > -> (equal? first car)<br>
>>> >> > #f<br>
>>> >> > -> (equal? last cdr)<br>
>>> >> > #f<br>
>>> >> > -> (equal? empty? null?)<br>
>>> >> > #f<br>
>>> >> ><br>
>>> >> ><br>
>>> >> > I suppose that they could be separate functions that happen to do the<br>
>>> >> > same<br>
>>> >> > thing, but if so, my next question would be why they aren't just<br>
>>> >> > aliases. As<br>
>>> >> > in:<br>
>>> >> ><br>
>>> >> > -> (define myfirst car)<br>
>>> >> > -> (equal? myfirst car)<br>
>>> >> > #t<br>
>>> >> ><br>
>>> >> > Cheers,<br>
>>> >> > Daniel.<br>
>>> >> > --<br>
>>> >> > When an engineer says that something can't be done, it's a code<br>
>>> >> > phrase<br>
>>> >> > that<br>
>>> >> > means it's not fun to do.<br>
>>> >> ><br>
>>> >> > ____________________<br>
>>> >> > Racket Users list:<br>
>>> >> > <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>>> >> ><br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >> --<br>
>>> >> --<br>
>>> >> Jens Axel Søgaard<br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> > --<br>
>>> > When an engineer says that something can't be done, it's a code phrase<br>
>>> > that<br>
>>> > means it's not fun to do.<br>
>>><br>
>>><br>
>>><br>
>>> --<br>
<span><font color="#888888">>>> --<br>
>>> Jens Axel Søgaard<br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>> When an engineer says that something can't be done, it's a code phrase that<br>
>> means it's not fun to do.<br>
>><br>
>> ____________________<br>
>> Racket Users list:<br>
>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.<br>
</div>
</div></div><br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>