* Value history
@ 2002-08-05 3:12 Greg Hewgill
2002-08-08 17:46 ` Marius Vollmer
0 siblings, 1 reply; 4+ messages in thread
From: Greg Hewgill @ 2002-08-05 3:12 UTC (permalink / raw)
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)
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Value history
2002-08-05 3:12 Value history Greg Hewgill
@ 2002-08-08 17:46 ` Marius Vollmer
2002-08-08 21:32 ` Neil Jerram
0 siblings, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 2002-08-08 17:46 UTC (permalink / raw)
Cc: guile-devel
Greg Hewgill <greg@hewgill.com> writes:
> Below is a patch for the "Value history" idea. This diff is against
> the CVS head.
Excellent! Thanks!
> 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.
Yes, eval is not the most direct way to do what you want. You can
also use
(module-define! (current-module) (string->symbol ...) result)
I think it is also important to have a way to switch the history off,
and to limit it to a maximum number of levels. Otherwise, an
arbitrary amount of uncollectable garbage might built up without the
user being aware of it.
You can use
(module-remove! (current-module)
(module-local-variable (current-module) sym))
to undefine variables in the current module. Might be worth to define
'module-undefine!'...
If you could make these changes, that would be great!
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Value history
2002-08-08 17:46 ` Marius Vollmer
@ 2002-08-08 21:32 ` Neil Jerram
2002-08-08 23:14 ` Marius Vollmer
0 siblings, 1 reply; 4+ messages in thread
From: Neil Jerram @ 2002-08-08 21:32 UTC (permalink / raw)
Cc: Marius Vollmer, guile-devel
>>>>> "Marius" == Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:
Marius> Greg Hewgill <greg@hewgill.com> writes:
>> Below is a patch for the "Value history" idea. This diff is against
>> the CVS head.
Marius> Excellent! Thanks!
However, we already have (ice-9 history), written by Keisuke. (I'm
afraid the web page is out of date.) Perhaps you could compare your
implementation and his, and combine the best features of both?
Neil
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Value history
2002-08-08 21:32 ` Neil Jerram
@ 2002-08-08 23:14 ` Marius Vollmer
0 siblings, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2002-08-08 23:14 UTC (permalink / raw)
Cc: Greg Hewgill, guile-devel
Neil Jerram <neil@ossau.uklinux.net> writes:
> >>>>> "Marius" == Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:
>
> Marius> Greg Hewgill <greg@hewgill.com> writes:
> >> Below is a patch for the "Value history" idea. This diff is against
> >> the CVS head.
>
> Marius> Excellent! Thanks!
>
> However, we already have (ice-9 history), written by Keisuke.
Oops. Didn't know about it.
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-08-08 23:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-05 3:12 Value history Greg Hewgill
2002-08-08 17:46 ` Marius Vollmer
2002-08-08 21:32 ` Neil Jerram
2002-08-08 23:14 ` Marius Vollmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).