* How to detect a procedure @ 2002-04-28 20:35 Bruce Korb 2002-04-29 4:52 ` bitwize 0 siblings, 1 reply; 12+ messages in thread From: Bruce Korb @ 2002-04-28 20:35 UTC (permalink / raw) OK. If: (if (procedure? 'mumble) (mumble)) doesn't work, what does? I keep trying different things to no avail. This is very, very frustrating. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-04-28 20:35 How to detect a procedure Bruce Korb @ 2002-04-29 4:52 ` bitwize 2002-04-29 9:45 ` rm 2002-04-30 0:00 ` Lynn Winebarger 0 siblings, 2 replies; 12+ messages in thread From: bitwize @ 2002-04-29 4:52 UTC (permalink / raw) Cc: guile-devel On Sun, 28 Apr 2002, Bruce Korb wrote: > > OK. If: > > (if (procedure? 'mumble) (mumble)) > > doesn't work, what does? I keep trying different things > to no avail. This is very, very frustrating. First of all, this type of thing is better off posted to guile-user instead of guile-devel (where nitty-gritty implementation details are mainly discussed). Secondly, the answer to your query is, procedures are stored in the same namespace as ordinary variables; (procedure? mumble) returns #t if mumble names a prevoiusly defined procedure. There is no need to quote, e.g. 'mumble, or to use the Common LISP convention #'mumble. Note that this applies to primitives, too; (procedure? procedure?) returns #t. :) -- Jeffrey T. Read "LOBSTER STICKS TO MAGNET!" _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-04-29 4:52 ` bitwize @ 2002-04-29 9:45 ` rm 2002-04-30 0:00 ` Lynn Winebarger 1 sibling, 0 replies; 12+ messages in thread From: rm @ 2002-04-29 9:45 UTC (permalink / raw) Cc: Bruce Korb, guile-devel On Mon, Apr 29, 2002 at 06:52:28AM +0200, bitwize@wizards-of-source.org wrote: > On Sun, 28 Apr 2002, Bruce Korb wrote: > > > > > OK. If: > > > > (if (procedure? 'mumble) (mumble)) > > > > doesn't work, what does? I keep trying different things > > to no avail. This is very, very frustrating. > > First of all, this type of thing is better off posted to guile-user > instead of guile-devel (where nitty-gritty implementation details are > mainly discussed). > > Secondly, the answer to your query is, procedures are stored in the same > namespace as ordinary variables; (procedure? mumble) returns #t if mumble > names a prevoiusly defined procedure. There is no need to quote, e.g. > 'mumble, or to use the Common LISP convention #'mumble. Well, there's no need to quote, but if mumble _isn't_ defined than (procedure? mumble) will barf ... The most stable approach would be: (and (defined 'blub) (procedure? blub)) and the conditional execution could be done like this: (if (and (defined 'blub) (procedure? blub)) (blub ...) (error "You need a newer version of transmogrify!")) Ralf Mattes > Note that this applies to primitives, too; (procedure? procedure?) returns > #t. :) > > -- > Jeffrey T. Read > "LOBSTER STICKS TO MAGNET!" > > > _______________________________________________ > Guile-devel mailing list > Guile-devel@gnu.org > http://mail.gnu.org/mailman/listinfo/guile-devel _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-04-29 4:52 ` bitwize 2002-04-29 9:45 ` rm @ 2002-04-30 0:00 ` Lynn Winebarger 2002-04-30 0:36 ` Bruce Korb 1 sibling, 1 reply; 12+ messages in thread From: Lynn Winebarger @ 2002-04-30 0:00 UTC (permalink / raw) Cc: guile-devel On Sunday 28 April 2002 23:52, bitwize@wizards-of-source.org wrote: > On Sun, 28 Apr 2002, Bruce Korb wrote: > Secondly, the answer to your query is, procedures are stored in the same > namespace as ordinary variables; (procedure? mumble) returns #t if mumble > names a prevoiusly defined procedure. There is no need to quote, e.g. > 'mumble, or to use the Common LISP convention #'mumble. I don't think this captures the spirit of the original question. If you do this, you rely on the evaluator checking for the existence of the binding - procedure? gets the actual object (it never sees the name). Or, if the name hasn't been bound it will error out (if the lookup throws an exception, that might be used). Lynn _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-04-30 0:00 ` Lynn Winebarger @ 2002-04-30 0:36 ` Bruce Korb 2002-04-30 13:50 ` Rob Browning 0 siblings, 1 reply; 12+ messages in thread From: Bruce Korb @ 2002-04-30 0:36 UTC (permalink / raw) Cc: bitwize, guile-devel Lynn Winebarger wrote: > I don't think this captures the spirit of the original question. If you do this, > you rely on the evaluator checking for the existence of the binding - procedure? > gets the actual object (it never sees the name). Or, if the name hasn't been > bound it will error out (if the lookup throws an exception, that might be used). How about adding this procedure. I confess to being uncertain if it actually works, I get lost trying to decipher the maze of macros. SCM_DEFINE (scm_defined_as_p, "defined-as?", 2, 1, 0, (SCM sym, SCM class, SCM env), "Return @code{#t} if @var{sym} is defined of class @var{class} in " "the lexical environment @var{env}. When @var{env} is not " "specified, look in the top-level environment as defined by the " "current module.") #define FUNC_NAME s_scm_defined_as_p { SCM var; SCM_VALIDATE_SYMBOL (1,sym); if (SCM_UNBNDP (env)) var = scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_F); else { SCM frames = env; register SCM b; for (; SCM_NIMP (frames); frames = SCM_CDR (frames)) { SCM_ASSERT (SCM_CONSP (frames), env, SCM_ARG2, FUNC_NAME); b = SCM_CAR (frames); if (SCM_NFALSEP (scm_procedure_p (b))) break; SCM_ASSERT (SCM_CONSP (b), env, SCM_ARG2, FUNC_NAME); for (b = SCM_CAR (b); SCM_NIMP (b); b = SCM_CDR (b)) { if (SCM_NCONSP (b)) { if (SCM_EQ_P (b, sym)) return SCM_BOOL_T; else break; } if (SCM_EQ_P (SCM_CAR (b), sym)) return SCM_BOOL_T; } } var = scm_sym2var (sym, SCM_NIMP (frames) ? SCM_CAR (frames) : SCM_BOOL_F, SCM_BOOL_F); } if (SCM_FALSEP (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))) return SCM_BOOL_F; if (scm_class_of (SCM_VARIABLE_REF (var)) == class) return SCM_BOOL_T; return SCM_BOOL_F; } #undef FUNC_NAME == Bruce Korb <first initial + last name at gnu dot org> AG URL: http://autogen.sourceforge.net _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-04-30 0:36 ` Bruce Korb @ 2002-04-30 13:50 ` Rob Browning 2002-05-01 1:22 ` Bruce Korb 0 siblings, 1 reply; 12+ messages in thread From: Rob Browning @ 2002-04-30 13:50 UTC (permalink / raw) Cc: Lynn Winebarger, bitwize, guile-devel Bruce Korb <bkorb@pacbell.net> writes: > How about adding this procedure. I confess to being uncertain if it > actually works, I get lost trying to decipher the maze of macros. Why this over "defined?"? Not opposed, just wanted to make sure I understood the intention. -- Rob Browning rlb @defaultvalue.org, @linuxdevel.com, and @debian.org Previously @cs.utexas.edu GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-04-30 13:50 ` Rob Browning @ 2002-05-01 1:22 ` Bruce Korb 2002-05-01 2:35 ` Rob Browning 0 siblings, 1 reply; 12+ messages in thread From: Bruce Korb @ 2002-05-01 1:22 UTC (permalink / raw) Cc: Lynn Winebarger, bitwize, guile-devel Rob Browning wrote: > > How about adding this procedure. I confess to being uncertain if it > > actually works, I get lost trying to decipher the maze of macros. > > Why this over "defined?"? > > Not opposed, just wanted to make sure I understood the intention. The scheme scripts for autogen may be written for a version or environment where a procedure is defined. Later, someone may run the script in another environment without that function. (e.g., with a retrograde autogen) So, yes, ``(defined? 'mumble)'' is probably adequate. I don't care a whole lot for "probably adequate". So, I would like: (defined-as? 'mumble scm_class_procedure) to be equivalent to: (and (defined? 'mumble) (procedure? mumble)) but the latter is conceptually simpler. I like simple. It's a more rigorous test (though it can still be fooled). [[It saves typing two characters, too. ;-) **joke!!**]] A similar scheme could have replaced the myriad of "procedure?" "pair?" "struct?" "symbol?" ... procedures so you would automatically have such a function available for any new class. Too late now, methinks. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-05-01 1:22 ` Bruce Korb @ 2002-05-01 2:35 ` Rob Browning 2002-05-01 2:46 ` Lynn Winebarger 0 siblings, 1 reply; 12+ messages in thread From: Rob Browning @ 2002-05-01 2:35 UTC (permalink / raw) Cc: Lynn Winebarger, bitwize, guile-devel Bruce Korb <bkorb@pacbell.net> writes: > I would like: > > (defined-as? 'mumble scm_class_procedure) > > to be equivalent to: > > (and (defined? 'mumble) (procedure? mumble)) > > but the latter is conceptually simpler. I like simple. or if you really like the idea of a helper, perhaps (nb: not tested, or even carefully checked :>): (define-macro (defined-as? item predicate) `(and (defined? ,item) (,predicate ,item))) i.e. (defined-as? 'mumble procedure?) -- Rob Browning rlb @defaultvalue.org, @linuxdevel.com, and @debian.org Previously @cs.utexas.edu GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-05-01 2:35 ` Rob Browning @ 2002-05-01 2:46 ` Lynn Winebarger 2002-05-01 3:39 ` Rob Browning 0 siblings, 1 reply; 12+ messages in thread From: Lynn Winebarger @ 2002-05-01 2:46 UTC (permalink / raw) Cc: bitwize, guile-devel On Tuesday 30 April 2002 21:35, Rob Browning wrote: > Bruce Korb <bkorb@pacbell.net> writes: > > > I would like: > > > > (defined-as? 'mumble scm_class_procedure) > > > > to be equivalent to: > > > > (and (defined? 'mumble) (procedure? mumble)) > > > > but the latter is conceptually simpler. I like simple. > > or if you really like the idea of a helper, perhaps (nb: not tested, > or even carefully checked :>): > > (define-macro (defined-as? item predicate) > `(and (defined? ,item) (,predicate ,item))) > > i.e. > > (defined-as? 'mumble procedure?) How about (defined-as procedure? 'mumble) to keep the predicate clear? Lynn _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-05-01 2:46 ` Lynn Winebarger @ 2002-05-01 3:39 ` Rob Browning 2002-05-01 21:36 ` Bruce Korb 0 siblings, 1 reply; 12+ messages in thread From: Rob Browning @ 2002-05-01 3:39 UTC (permalink / raw) Cc: Bruce Korb, bitwize, guile-devel Lynn Winebarger <owinebar@free-expression.org> writes: >> (defined-as? 'mumble procedure?) > > How about (defined-as procedure? 'mumble) > to keep the predicate clear? Looks better to me :> -- Rob Browning rlb @defaultvalue.org, @linuxdevel.com, and @debian.org Previously @cs.utexas.edu GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-05-01 3:39 ` Rob Browning @ 2002-05-01 21:36 ` Bruce Korb 2002-05-01 22:18 ` Neil Jerram 0 siblings, 1 reply; 12+ messages in thread From: Bruce Korb @ 2002-05-01 21:36 UTC (permalink / raw) Cc: Lynn Winebarger, bitwize, guile-devel Rob Browning wrote: > > Lynn Winebarger <owinebar@free-expression.org> writes: > > >> (defined-as? 'mumble procedure?) > > > > How about (defined-as procedure? 'mumble) > > to keep the predicate clear? > > Looks better to me :> Me, too :) _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to detect a procedure 2002-05-01 21:36 ` Bruce Korb @ 2002-05-01 22:18 ` Neil Jerram 0 siblings, 0 replies; 12+ messages in thread From: Neil Jerram @ 2002-05-01 22:18 UTC (permalink / raw) Cc: Rob Browning, Lynn Winebarger, bitwize, guile-devel >>>>> "Bruce" == Bruce Korb <bkorb@pacbell.net> writes: Bruce> Rob Browning wrote: >> >> Lynn Winebarger <owinebar@free-expression.org> writes: >> >> >> (defined-as? 'mumble procedure?) >> > >> > How about (defined-as procedure? 'mumble) >> > to keep the predicate clear? >> >> Looks better to me :> Bruce> Me, too :) But I think Rob's definition was missing a quote. This works for me: (define-macro (defined-as predicate symbol) `(and (defined? ',symbol) (,predicate ,symbol))) guile> (defined-as procedure? procedure?) #t guile> (defined-as procedure? does-not-exist) #f guile> (defined-as procedure? defined-as) #f guile> (defined-as macro? defined-as) #t guile> (defined-as procedure? %load-path) #f guile> (defined-as list? %load-path) #t Neil _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2002-05-01 22:18 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2002-04-28 20:35 How to detect a procedure Bruce Korb 2002-04-29 4:52 ` bitwize 2002-04-29 9:45 ` rm 2002-04-30 0:00 ` Lynn Winebarger 2002-04-30 0:36 ` Bruce Korb 2002-04-30 13:50 ` Rob Browning 2002-05-01 1:22 ` Bruce Korb 2002-05-01 2:35 ` Rob Browning 2002-05-01 2:46 ` Lynn Winebarger 2002-05-01 3:39 ` Rob Browning 2002-05-01 21:36 ` Bruce Korb 2002-05-01 22:18 ` Neil Jerram
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).