unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* ADD type-of
@ 2011-12-27  6:24 Nala Ginrut
  2011-12-27  6:25 ` Nala Ginrut
  2011-12-27  7:17 ` Daniel Hartwig
  0 siblings, 2 replies; 4+ messages in thread
From: Nala Ginrut @ 2011-12-27  6:24 UTC (permalink / raw)
  To: guile-devel


[-- Attachment #1.1: Type: text/plain, Size: 247 bytes --]

A newbie Guiler asked me if there's something like "typeof" as "type" in
Python or "typeof" in JS.
I can't remember there's such a thing. But I think it'll provide
some convenient for a newbie to learn Guile.
Here's my patch.
What you guys think?

[-- Attachment #1.2: Type: text/html, Size: 332 bytes --]

[-- Attachment #2: 0002-ADD-type-of-to-goops.scm.patch --]
[-- Type: text/x-patch, Size: 1237 bytes --]

From 4518a8e05c027895e2e2f341273326b520259636 Mon Sep 17 00:00:00 2001
From: NalaGinrut <NalaGinrut@gmail.com>
Date: Tue, 27 Dec 2011 14:19:39 +0800
Subject: [PATCH 2/2] ADD type-of to goops.scm

---
 module/oop/goops.scm |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index e4424f3..d9eb583 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -72,7 +72,7 @@
 	   method-specializers method-formals
 	   primitive-generic-generic enable-primitive-generic!
 	   method-procedure accessor-method-slot-definition
-	   slot-exists? make find-method get-keyword)
+	   slot-exists? make find-method get-keyword type-of)
   :no-backtrace)
 
 (define *goops-module* (current-module))
@@ -1654,6 +1654,17 @@
   (list2set (mapappend class-direct-methods
 		       (cons c (class-subclasses c)))))
 
+(define (type-of x)
+  (cond 
+   ((is-a? x <unknown>) '<undefined>)
+   ((null? x) '<object>)
+   ((is-a? x <boolean>) '<boolean>)
+   ((is-a? x <integer>) '<integer>)
+   ((is-a? x <string>) '<string>)
+   ((is-a? x <procedure>) '<function>)
+   ((is-a? x <object>) '<object>)
+   (else '<scm>)))
+
 ;;;
 ;;; {Final initialization}
 ;;;
-- 
1.7.0.4


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

end of thread, other threads:[~2011-12-27  7:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-27  6:24 ADD type-of Nala Ginrut
2011-12-27  6:25 ` Nala Ginrut
2011-12-27  7:17 ` Daniel Hartwig
2011-12-27  7:29   ` Nala Ginrut

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