unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Marco Maggi" <marco.maggi-ipsu@poste.it>
To: "guile-user" <guile-user@gnu.org>
Subject: Re: Guile Introspection
Date: Mon,  9 Jul 2007 08:28:46 +0200	[thread overview]
Message-ID: <JKWFBY$DA5EE9706CF7574AC49315101A0F8C22@poste.it> (raw)

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


             reply	other threads:[~2007-07-09  6:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-09  6:28 Marco Maggi [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-07-10 12:51 Guile Introspection 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='JKWFBY$DA5EE9706CF7574AC49315101A0F8C22@poste.it' \
    --to=marco.maggi-ipsu@poste.it \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).