Appending to lists in Lazy Racket

10 views
Skip to first unread message

Spencer Weight

unread,
Dec 7, 2013, 5:09:56 PM12/7/13
to byu-cs-330...@googlegroups.com
Here is some code that I have been toying with

*******************************************************
#lang lazy

(define primes (list 2 3 5 7 11))

(if (andmap (lambda (x)
               (if (= 0 (modulo 13 x))
                   #f
                   #t))
             primes)
     (append primes 13)
     primes)

(list-ref primes 5)
*******************************************************

I need a bit of direction.
I know that a few things are handled differently in lazy Racket and this is probably why I'm getting the error:
list-ref: expected argument of type <proper list>; given: '()

My question is how do I append to the end of a list in lazy Racket

Andrew Kent

unread,
Dec 7, 2013, 5:28:46 PM12/7/13
to Spencer Weight, BYU CS 330 Fall 2013
Here's some random comments that may help fix that (and make your code more clear):

(if exp #f #t) is the same as (not exp)... isn't it?

(zero? x) can be used instead of (= 0 x)

append appends lists together (usually, anyway). You are concatenating something of type list with something of type num - is that what you meant to do? See the doc linked above.



--
You received this message because you are subscribed to the Google Groups "byu-cs-330-fall-2013" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byu-cs-330-fall-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
-Andrew

Spencer Weight

unread,
Dec 7, 2013, 5:42:12 PM12/7/13
to byu-cs-330...@googlegroups.com, Spencer Weight
Thanks, that helped :)
Reply all
Reply to author
Forward
0 new messages