Paste number 80963: a question about the definition of the variable arity function in "Clojure: A Dynamic Programming Language for the JVM," by Rich Hickey

Index of paste annotations: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

Paste number 80963: a question about the definition of the variable arity function in "Clojure: A Dynamic Programming Language for the JVM," by Rich Hickey
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ
Channel:#clojure
Paste contents:
Raw Source | XML | Display As
On slide 20 of the talk "Clojure: A Dynamic Programming Language for
the JVM" (see
ftp://lispnyc.org/meeting-assets/2007-11-13_clojure/clojuretalk.pdf),
by Rich Hickey, the following function and evaluation results are
defined:

>(defn argcount
>  ([] 0)
>  ([x] 1)
>  ([x y] 2)
>  ([x y & more]
>     (+ (thisfn x y) (count more))))
>
>(argcount 1 2 3 4 5)
>-> 5

However, when I evaluate this function in the REPL, the following
error is returned:

>java.lang.Exception: Unable to resolve symbol: thisfn in this context (NO_SOURCE_FILE:6)
>  [Thrown class clojure.lang.Compiler$CompilerException]

However, no definition is given for "thisfn" in the talk.

Forgive me if I am missing something very obvious, but does anybody
know where I can find the definition of "thisfn"?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto." 
-- Matsuo Basho^ 

Annotations for this paste:

Annotation number 1: PLT-Scheme-specific Version 1.1.1 of Towers of Hanoi
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/1
Paste contents:
Raw Source | Display As
;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(planet plai/plai:1:1/lang/reader)
;; Towers of Hanoi, plt1.1.1
;; PLT-Scheme-specific Version 1.1.1 of Towers of Hanoi
;; 
;; Usage: (hanoi n), where n is the number of discs to move from the source peg to the destination peg
;; 
;; Copyright(C) April 13, 2009, at 17:17, 
;; by Benjamin L. Russell
;; 
;; Update History:
;; 
;; Version 1.1.1
;; Transposed phrase "... from disc" to "... disc from" in printf statement; added usage information.

(define (hanoi n)
  (hanoi-helper 'A 'B 'C n))

(define (hanoi-helper source using destination n)
  (cond ((= n 1)
         (printf "Moving disc from ~a to ~a.\n" source destination))
        (else
         (hanoi-helper source destination using (- n 1))
         (hanoi-helper source using destination 1)
         (hanoi-helper using source destination (- n 1)))))

Annotation number 2: PLT-Scheme-specific Version 1.1.1 of Towers of Hanoi
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/2
Paste contents:
Raw Source | Display As
(defun hanoi (n)
	   (hanoi-helper n 'A 'B 'C))
(defun hanoi-helper (n source dest using)
	   (cond ((equalp n 1) (format nil "Move disc from ~A to ~A." source dest))
		 (t (hanoi-helper (- n 1) source using dest)
		    (hanoi-helper 1 source dest using)
		    (hanoi-helper (- n 1) using dest source))))

CL-USER> (hanoi 1)
"Move disc from A to B."
CL-USER> (hanoi 2)
"Move disc from C to B."

Annotation number 3: Clojure version of Towers of Hanoi
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/3
Paste contents:
Raw Source | Display As
(defn hanoi [n]
  (defn hanoi-helper [n source dest using]
    (cond
      (= n 1) (println (format "Move disc from %s to %s." source dest))
      :else (do
	      (hanoi-helper (- n 1) source using dest)
	      (hanoi-helper 1 source dest using)
	      (hanoi-helper (- n 1) using dest source))))
  (hanoi-helper n 'A 'B 'C))

Annotation number 4: Revised Clojure Towers of Hanoi function
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/4
Paste contents:
Raw Source | Display As
(defn hanoi [n]
  (let [hanoi-helper (fn [n source dest using]
    (cond
      (= n 1) (println (format "Move disc from %s to %s." source dest))
      :else (do
	      (hanoi-helper (- n 1) source using dest)
	      (hanoi-helper 1 source dest using)
	      (hanoi-helper (- n 1) using dest source))))])
  (hanoi-helper n 'A 'B 'C))

Annotation number 5: hanoi using letfn
Pasted by: rhickey
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/5
Paste contents:
Raw Source | Display As
(defn hanoi [n]
  (letfn [(hanoi-helper [n source dest using]
            (cond
             (= n 1) (println (format "Move disc from %s to %s." source dest))
             :else (do
                     (hanoi-helper (- n 1) source using dest)
                     (hanoi-helper 1 source dest using)
                     (hanoi-helper (- n 1) using dest source))))]
         (hanoi-helper n 'A 'B 'C)))

Annotation number 6: This Clojure code didn't work....
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/6
Paste contents:
Raw Source | Display As
(defn hanoi [n]
  (let [hanoi-helper (fn hanoi-helper [n source dest using]
    (cond
      (= n 1) (println (format "Move disc from %s to %s." source dest))
      :else (do
	      (hanoi-helper (- n 1) source using dest)
	      (hanoi-helper 1 source dest using)
	      (hanoi-helper (- n 1) using dest source))))])
  (hanoi-helper n 'A 'B 'C))

Annotation number 7: broken CL Towers of Hanoi program and result
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/7
Paste contents:
Raw Source | Display As
(defun hanoi (n)
	   (hanoi-helper n 'A 'B 'C))

(defun hanoi-helper (n source dest using)
	   (cond ((equalp n 1) (format t "Move disc from ~A to ~A.~%" source dest))
		 (t (progn
		      (hanoi-helper (- n 1) source using dest)
		      (hanoi-helper 1 source dest using)
		      (hanoi-helper (- n 1) using dest source)))))
HANOI-HELPER
CL-USER> (hanoi 3)
NIL
CL-USER> 

Annotation number 8: finish-output didn't work....
Pasted by: DekuDekuplex
When:8 months, 1 week ago
Share:Tweet this! | http://paste.lisp.org/+1QGZ/8
Paste contents:
Raw Source | Display As
CL-USER> (defun hanoi (n)
	   (hanoi-helper n 'A 'B 'C))

(defun hanoi-helper (n source dest using)
	   (cond ((equalp n 1) (format t "Move disc from ~A to ~A.~%" source dest))
		 (t (progn
		      (hanoi-helper (- n 1) source using dest)
		      (hanoi-helper 1 source dest using)
		      (hanoi-helper (- n 1) using dest source)))))
HANOI-HELPER
CL-USER> (hanoi 3)
NIL
CL-USER> (finish-output)
NIL
CL-USER> 

Colorize as:
Show Line Numbers
Index of paste annotations: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.