unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: Guile Introspection
@ 2007-07-10 12:51 Marco Maggi
  0 siblings, 0 replies; 8+ messages in thread
From: Marco Maggi @ 2007-07-10 12:51 UTC (permalink / raw)
  To: guile-user

"Mike Gran" wrote:
>what is the scheme version of the following C code
>
>printf("%s %d\n", __FILE__, __LINE__);

A better solution[1] than the other I posted. Still far
from perfect.

[1]
<http://community.schemewiki.org/?guile-function-and-file-name>

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Guile Introspection
@ 2007-07-09  6:28 Marco Maggi
  0 siblings, 0 replies; 8+ messages in thread
From: Marco Maggi @ 2007-07-09  6:28 UTC (permalink / raw)
  To: guile-user

Ciao,

"Mike Gran" wrote:
>Or, what is the scheme version of the following C code
>
>printf("%s %d\n", __FILE__, __LINE__);

I like a solution that redefines DEFINE without introducing
an environment in the body of the function. To do it: you
have to take the body in question and treat it as a tree,
mapping selected symbols to the values you want.

If I am correct in assuming that you are a Scheme beginner
and the following code is no clear enough, just ask.

;; ----------------------------------------

(define (map-tree func tree)
  (map (lambda (v)
	 (if (list? v)
	     (map-tree func v)
	   (func v))) tree))

(define (subst-tree old new tree)
  (map-tree (lambda (v)
	      (if (eq? old v) new v)) tree))

(define saved-define define)

;; ----------------------------------------

(define *current-file-name* "proof.scm")

(define-macro (define name-and-args . body)
  (let* ((fname	(symbol->string (car name-and-args)))
	 (args	(cdr name-and-args))
	 (body1 (subst-tree
		 '*current-file-name* *current-file-name*
		 (subst-tree '*current-function-name* fname body))))
    `(saved-define ,name-and-args ,@body1)))

;; ----------------------------------------
;; tests

(define (my-func)
  (format #t "file: ~A, func: ~A~%"
	  *current-file-name*
	  *current-function-name*))

(define (other-func alpha beta)
  (format #t "file: ~A, func: ~A, a ~A, b ~A~%"
	  *current-file-name*
	  *current-function-name*
	  alpha beta))

(define (further-func . args)
  (apply format #t "file: ~A, func: ~A, a ~A, b ~A~%"
	 *current-file-name*
	 *current-function-name*
	 args))

(my-func)
(other-func 123 'abc)
(further-func 123 'abc)

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Guile Introspection
@ 2007-07-07 15:40 Mike Gran
  2007-07-08  0:18 ` Issac Trotts
  2007-07-08 15:18 ` Ludovic Courtès
  0 siblings, 2 replies; 8+ messages in thread
From: Mike Gran @ 2007-07-07 15:40 UTC (permalink / raw)
  To: Gule User

Hi-

Is it possible to get introspection information out of Guile
(preferably without having to load GOOPS)?

For example, how can I write a function that prints its own name?

Or, what is the scheme version of the following C code

printf("%s %d\n", __FILE__, __LINE__);

Thanks in advance,

Mike Gran


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-07-12 13:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-10 12:51 Guile Introspection Marco Maggi
  -- strict thread matches above, loose matches on Subject: below --
2007-07-09  6:28 Marco Maggi
2007-07-07 15:40 Mike Gran
2007-07-08  0:18 ` Issac Trotts
2007-07-08 15:18 ` Ludovic Courtès
2007-07-09 10:57   ` Andy Wingo
2007-07-09 12:35     ` Ludovic Courtès
2007-07-12 13:09     ` Thien-Thi Nguyen

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).