I think I am thinking too imperatively and not declaratively

8 views
Skip to first unread message

Willard Hagen

unread,
Dec 10, 2013, 11:28:07 PM12/10/13
to byu-cs-330...@googlegroups.com
Is this a declarative function?

(define (prime?/fast n)
      (define myprime #t)
      (for-each
      (λ (x) (if (and (not (eq? n x)) (zero? (modulo n x))) (set! myprime #f) empty)) (list 2 3 5 7))
      myprime
  )

Jay McCarthy

unread,
Dec 10, 2013, 11:34:01 PM12/10/13
to Willard Hagen, BYU CS 330 Fall 2013
No. You can tell because you are using for-each which is only called
for effect and set! which is an effect.
> --
> 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.



--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Jay McCarthy

unread,
Dec 10, 2013, 11:57:57 PM12/10/13
to Willard Hagen, BYU CS 330 Fall 2013
Ye

On Tue, Dec 10, 2013 at 9:39 PM, Willard Hagen <willar...@gmail.com> wrote:
> So using maps would be a sign of thinking declaratively?
> --
> -Willard
Reply all
Reply to author
Forward
0 new messages