* 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
* Re: ADD type-of
2011-12-27 6:24 ADD type-of Nala Ginrut
@ 2011-12-27 6:25 ` Nala Ginrut
2011-12-27 7:17 ` Daniel Hartwig
1 sibling, 0 replies; 4+ messages in thread
From: Nala Ginrut @ 2011-12-27 6:25 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1.1: Type: text/plain, Size: 365 bytes --]
Sorry, missed another one.
On Tue, Dec 27, 2011 at 2:24 PM, Nala Ginrut <nalaginrut@gmail.com> wrote:
> 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: 671 bytes --]
[-- Attachment #2: 0001-ADD-type-of-to-boot-9.scm.patch --]
[-- Type: text/x-patch, Size: 910 bytes --]
From 6075ad414b8c11a17647beef46d9e2dad3f3e110 Mon Sep 17 00:00:00 2001
From: NalaGinrut <NalaGinrut@gmail.com>
Date: Tue, 27 Dec 2011 14:18:49 +0800
Subject: [PATCH 1/2] ADD type-of to boot-9.scm
---
module/ice-9/boot-9.scm | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 03dad9b..43fce1c 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -3851,4 +3851,14 @@ module '(ice-9 q) '(make-q q-length))}."
;; `-Wunused-toplevel' warning works as expected.
(eval-when (compile) (set-current-module the-root-module))
+(define (type-of x)
+ (cond
+ ((eq? x *undefined*) '<undefined>)
+ ((null? x) '<object>)
+ ((boolean? x) '<boolean>)
+ ((number? x) '<number>)
+ ((string? x) '<string>)
+ ((procedure? x) '<function>)
+ (else '<scm>)))
+
;;; boot-9.scm ends here
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: ADD type-of
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
1 sibling, 1 reply; 4+ messages in thread
From: Daniel Hartwig @ 2011-12-27 7:17 UTC (permalink / raw)
To: Nala Ginrut; +Cc: guile-devel
On 27 December 2011 14:24, Nala Ginrut <nalaginrut@gmail.com> wrote:
> 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?
GOOPS has `class-of'[1] and `class-name':
scheme@(guile-user)> (use-modules (oop goops))
scheme@(guile-user)> (class-of 12)
$1 = #<<class> <integer> 99bef78>
scheme@(guile-user)> (class-name $1)
$2 = <integer>
[1] http://www.gnu.org/software/guile/manual/html_node/Instances.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ADD type-of
2011-12-27 7:17 ` Daniel Hartwig
@ 2011-12-27 7:29 ` Nala Ginrut
0 siblings, 0 replies; 4+ messages in thread
From: Nala Ginrut @ 2011-12-27 7:29 UTC (permalink / raw)
To: Daniel Hartwig; +Cc: guile-devel
[-- Attachment #1: Type: text/plain, Size: 796 bytes --]
hi Daniel, thanks for reminding me.
So the patch for GOOPS is redundant.
On Tue, Dec 27, 2011 at 3:17 PM, Daniel Hartwig <mandyke@gmail.com> wrote:
> On 27 December 2011 14:24, Nala Ginrut <nalaginrut@gmail.com> wrote:
> > 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?
>
> GOOPS has `class-of'[1] and `class-name':
>
> scheme@(guile-user)> (use-modules (oop goops))
> scheme@(guile-user)> (class-of 12)
> $1 = #<<class> <integer> 99bef78>
> scheme@(guile-user)> (class-name $1)
> $2 = <integer>
>
>
> [1] http://www.gnu.org/software/guile/manual/html_node/Instances.html
>
[-- Attachment #2: Type: text/html, Size: 1405 bytes --]
^ permalink raw reply [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).