[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Value history
From: |
Greg Hewgill |
Subject: |
Value history |
Date: |
Sun, 4 Aug 2002 22:12:15 -0500 |
User-agent: |
Mutt/1.4i |
I'm a guile newbie and thought it might be interesting to play with some of the
low hanging fruit on the "cool ideas" page. This is my first actual useful
scheme code, so please be gentle. :)
Below is a patch for the "Value history" idea. This diff is against the CVS
head. If anybody has any suggestions for improvement, let me know. I get the
feeling that the eval statement might not be the best way to do the global $<n>
assignment, but it was the only way I could find to make it work.
Greg Hewgill
http://www.hewgill.com
RCS file: /cvs/guile/guile-core/ice-9/boot-9.scm,v
retrieving revision 1.282
diff -c -r1.282 boot-9.scm
*** ice-9/boot-9.scm 7 Jul 2002 05:18:16 -0000 1.282
--- ice-9/boot-9.scm 5 Aug 2002 03:06:11 -0000
***************
*** 2282,2287 ****
--- 2282,2294 ----
(define before-print-hook (make-hook 1))
(define after-print-hook (make-hook 1))
+ ;;; A counter for numbering the results of interactive expressions
+ ;;; in the repl loop. $$ is always the value of the last printed
+ ;;; result. $<n> where <n> is an integer, is created in the -print
+ ;;; section of the repl loop below.
+ (define repl-counter 0)
+ (define $$ #f)
+
;;; The default repl-reader function. We may override this if we've
;;; the readline library.
(define repl-reader
***************
*** 2373,2378 ****
--- 2380,2392 ----
(if (or scm-repl-print-unspecified
(not (unspecified? result)))
(begin
+ (set! repl-counter (+
repl-counter 1))
+ (set! $$ result)
+ ;; we have to do this with an
eval so we can use define
+ (eval
+ `(define ,(string->symbol
(string-append "$" (number->string repl-counter))) $$)
+ (interaction-environment))
+ (display (string-append "$"
(number->string repl-counter) " => "))
(write result)
(newline))))))
(lambda (result)
- Value history,
Greg Hewgill <=