Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Functions that churn out lambdas - when?

Name: Anonymous 2009-09-12 1:29

I just wrote my own "repeated" implementation (SICP lecture 3x), and I thought the same could have been done with something of the format (repeated procedure item times), instead of dealing with another layer of abstraction by churning out a procedure that does the actual iteration ((repeated procedure times) item). At this point, choosing between both forms seems like an arbitrary flip of the coin - can anyone on /prog/ enlighten me?

Name: Anonymous 2009-09-12 8:11

(and if you must absolutely do it like >>2)

(defmacro repeated (n)
  `(lambda (f)
      (lambda (item)
        (dotimes (n ,n) (funcall f item)))))

Note you can use &rest items and APPLY instead of FUNCALL (but then f might be called as an 0-ary function).

Use:

(funcall (funcall (repeated 10) #'princ) '|SICP |)
SICP SICP SICP SICP SICP SICP SICP SICP SICP SICP
NIL

Never said it's going to look pretty!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List