unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Getting a type of a variable
@ 2008-07-18 21:48 Maciek Godek
  2008-07-19  8:53 ` Andy Wingo
  2008-07-20 20:48 ` Ludovic Courtès
  0 siblings, 2 replies; 3+ messages in thread
From: Maciek Godek @ 2008-07-18 21:48 UTC (permalink / raw
  To: guile-user

Hello,
I'm looking for an efficient way to check the
type of an SCM variable. I imagine that I
could write something like:
(define (type? x)
  (cond ((integer? x) 'int)
  (cond ((real? x) 'double)
...
)

and then convert guile symbol to C string, but that
would be terribly inefficient. (I could also use an integer
to refer to a type, but there's still this 'cond' clause)

The solution of my dreams is that it would turn out
that there's a function defined in the scm api:
scm_t_bits scm_get_type(SCM *var)
that returns a type tag and that there's a way to decipher
the contents of this return value, and that it is wisely
defined for all builtin types.

(I started to implement such thing by myself as a separate
module, but please inform me if it's already done)

Thanks in advance for help




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

* Re: Getting a type of a variable
  2008-07-18 21:48 Getting a type of a variable Maciek Godek
@ 2008-07-19  8:53 ` Andy Wingo
  2008-07-20 20:48 ` Ludovic Courtès
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2008-07-19  8:53 UTC (permalink / raw
  To: Maciek Godek; +Cc: guile-user

On Fri 18 Jul 2008 23:48, "Maciek Godek" <pstrychuj@gmail.com> writes:

> Hello,
> I'm looking for an efficient way to check the
> type of an SCM variable. I imagine that I
> could write something like:
> (define (type? x)
>   (cond ((integer? x) 'int)
>   (cond ((real? x) 'double)
> ...
> )

(oop goops)'s `class-of'

Andy
-- 
http://wingolog.org/




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

* Re: Getting a type of a variable
  2008-07-18 21:48 Getting a type of a variable Maciek Godek
  2008-07-19  8:53 ` Andy Wingo
@ 2008-07-20 20:48 ` Ludovic Courtès
  1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2008-07-20 20:48 UTC (permalink / raw
  To: guile-user

Hello,

"Maciek Godek" <pstrychuj@gmail.com> writes:

> The solution of my dreams is that it would turn out
> that there's a function defined in the scm api:
> scm_t_bits scm_get_type(SCM *var)
> that returns a type tag and that there's a way to decipher
> the contents of this return value, and that it is wisely
> defined for all builtin types.

If you are to dive into such low-level things, you could implement in
Scheme type tag "deciphering".  You'd use the `object-address'
procedure, and then re-implement type tag encoding/decoding from
"libguile/tags.h" at the Scheme level.  That'd be an interesting
exercise as the Scheme implementation would be readily understandable
(compared to obscure C macros and informal comments).

Otherwise, Andy's suggestion may be wiser.  ;-)

Thanks,
Ludovic.





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

end of thread, other threads:[~2008-07-20 20:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18 21:48 Getting a type of a variable Maciek Godek
2008-07-19  8:53 ` Andy Wingo
2008-07-20 20:48 ` Ludovic Courtès

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