0

I am trying to learn the use of delay and force in Scheme. I created a function which outputs the even numbers in the list. Now I am trying to use delay and force with function. But I am getting error : unbound symbol : "delay" [].

Can someone explain what I am doing wrong?

(define (even-filter ls)
  (if (null? ls)  '()
    (filter even? ls)))

(even-filter '(1 2 3 4 5 88))

(let ((delayed (delay (even-filter '(1 2 3 4 5 88)))))
  (force delayed))
Will Ness
  • 70,110
  • 9
  • 98
  • 181
Bikram Singh
  • 139
  • 1
  • 1
  • 9

1 Answers1

0

Make sure that you're using the right language, because both force and delay are primitive forms, part of the standard language. If using Racket, in the bottom-left corner select "Determine language from source", and type the following:

#lang racket

(define (even-filter ls)
  (filter even? ls))

(let ((delayed (delay (even-filter '(1 2 3 4 5 88)))))
  (force delayed))

It works as expected:

'(2 4 88)
Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • the indentation is botched , but `delayed` is *inside* the `let` which defined it. the error is *`unbound symbol : "delay"`* (some library loading problems? the implementation is not specified...) – Will Ness Mar 06 '16 at 15:27
  • @WillNess good catch! I rewrote my answer assuming that OP is using Racket, errors like this are common when the wrong language is selected. – Óscar López Mar 06 '16 at 15:59
  • 1
    I was using "repl.it" online interpreter, code did not work, but when I tried it on "Racket" it worked. Thanks – Bikram Singh Mar 07 '16 at 01:14