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^
;; 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)))))(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."
(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))(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))(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)))(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))(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>
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>