Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-05 Thread Stephen Eilert
On Sat, Mar 3, 2012 at 3:31 PM, Peter Bex peter@xs4all.nl wrote:

 But the disadvantage is of course that it also means you can't use the
 power of these facilities when they are called for (see also the lack of
 general SLIME integration for Scheme).


Precisely!

Being able to introspect and patch code at runtime could lead to nifty
development tools indeed, even if they were only available on 'csi'.


-- Stephen

*Kids these days.*
*Whatever happened to hard work?*

   -- Joel Spolsky, The perils of javaschools
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-03 Thread Peter Bex
On Fri, Mar 02, 2012 at 06:57:56PM -0700, Matt Welland wrote:
 I'm trying to convert a comparison operator to the equivalent text. These
 are not symbols. I think case treats the target list as if it was created
 with a quote: '(). Thus things are all symbols in the list and the eqv?
 returns false.
 
  (case  (() yup)(else nope))
 nope
  (cond ((eqv?  ) yup)(else nope))
 yup
 
 The cond does what I need just fine, I just didn't understand why case
 didn't also work.

Like others have said before, case implicitly quotes its arguments,
comparing the input to symbols.  Your cond is doing something entirely
different; taking the value of the identifiers and comparing the input to
those.

 Is there a more schemeish way to convert any of the operators to the text
 representation?
 
 (define gt )
 (op-string gt)
  = 

I think you're perhaps confused about the difference between one of many
possible textual representations of a program and its semantical meaning.

How is Scheme supposed to know the canonical name of a random lambda?
The only way is whatever arbitrarily chosen assignment you've decided on
in your program.  Having said that, you can extract the initial name
of a procedure, which is the name of the surrounding define when the
lambda was first introduced (or its C name in some cases):

#;1 (define (bar x) 1)
#;2 (define foo (lambda (y) y))
#;3 (let ((whatever (lambda (z) z)))
   ;; set! global value
   (set! qux whatever))
#;4 (##sys#lambda-info-string (##sys#lambda-info bar))
(bar x)
#;5 (##sys#lambda-info-string (##sys#lambda-info foo))
(foo y)
#;6 (##sys#lambda-info-string (##sys#lambda-info qux))
(whatever z)
#;7 (##sys#lambda-info-string (##sys#lambda-info +))
C_plus
#;8 ;; But look at this:
(use numbers)
#;9 (##sys#lambda-info-string (##sys#lambda-info +))
(numbers#+ . args176)

As you can see, this canonical name isn't something you
can easily influence.  Another way to solve this particilar
issue is to make an alist or hash table mapping your desired
canonical names to procedures, and op-string look up names
in this table.  A macro might also help in reducing work,
as it allows you to list just the canonical names of
procedures once and have it generate a case statement:

#;1
(define-syntax define-op-converter
  (syntax-rules ()
((_ name op0 ...)
 (define (name op)
   (select op
 ((op0) (symbol-string 'op0))
 ...
 (else (error unknown operator op)))
#;2 (define-op-converter op-string   + -)
#;3 (op-string )

#;4 ;; But there are many limitations:
(use numbers)
#;5 (op-string )
Error: unknown operator: #procedure (numbers# x11875 x21876 . xs1877)

Depending on what exactly you're trying to do in the bigger
picture, perhaps rethinking your approach is a better solution
than trying to work around this.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-03 Thread Matt Welland
On Sat, Mar 3, 2012 at 6:53 AM, Peter Bex peter@xs4all.nl wrote:

 On Fri, Mar 02, 2012 at 06:57:56PM -0700, Matt Welland wrote:
  I'm trying to convert a comparison operator to the equivalent text. These
  are not symbols. I think case treats the target list as if it was created
  with a quote: '(). Thus things are all symbols in the list and the eqv?
  returns false.
 
   (case  (() yup)(else nope))
  nope
   (cond ((eqv?  ) yup)(else nope))
  yup
 
  The cond does what I need just fine, I just didn't understand why case
  didn't also work.

 Like others have said before, case implicitly quotes its arguments,
 comparing the input to symbols.  Your cond is doing something entirely
 different; taking the value of the identifiers and comparing the input to
 those.

  Is there a more schemeish way to convert any of the operators to the text
  representation?
 
  (define gt )
  (op-string gt)
   = 

 I think you're perhaps confused about the difference between one of many
 possible textual representations of a program and its semantical meaning.

 How is Scheme supposed to know the canonical name of a random lambda?
 The only way is whatever arbitrarily chosen assignment you've decided on
 in your program.  Having said that, you can extract the initial name
 of a procedure, which is the name of the surrounding define when the
 lambda was first introduced (or its C name in some cases):


It sounds like the answer I was looking for is that there is no scheme
introspection that maps a procedure to the bound name. The question was
merely academic, the cond is fine. I like the select but prefer not to use
it as it may not be available out of the box should I ever need to
migrate to another scheme.


 #;1 (define (bar x) 1)
 #;2 (define foo (lambda (y) y))
 #;3 (let ((whatever (lambda (z) z)))
   ;; set! global value
   (set! qux whatever))
 #;4 (##sys#lambda-info-string (##sys#lambda-info bar))
 (bar x)
 #;5 (##sys#lambda-info-string (##sys#lambda-info foo))
 (foo y)
 #;6 (##sys#lambda-info-string (##sys#lambda-info qux))
 (whatever z)
 #;7 (##sys#lambda-info-string (##sys#lambda-info +))
 C_plus
 #;8 ;; But look at this:
 (use numbers)
 #;9 (##sys#lambda-info-string (##sys#lambda-info +))
 (numbers#+ . args176)

 As you can see, this canonical name isn't something you
 can easily influence.  Another way to solve this particilar
 issue is to make an alist or hash table mapping your desired
 canonical names to procedures, and op-string look up names
 in this table.  A macro might also help in reducing work,
 as it allows you to list just the canonical names of
 procedures once and have it generate a case statement:

 #;1
 (define-syntax define-op-converter
  (syntax-rules ()
((_ name op0 ...)
 (define (name op)
   (select op
 ((op0) (symbol-string 'op0))
 ...
 (else (error unknown operator op)))
 #;2 (define-op-converter op-string   + -)
 #;3 (op-string )
 
 #;4 ;; But there are many limitations:
 (use numbers)
 #;5 (op-string )
 Error: unknown operator: #procedure (numbers# x11875 x21876 . xs1877)

 Depending on what exactly you're trying to do in the bigger
 picture, perhaps rethinking your approach is a better solution
 than trying to work around this.


Thanks for the detailed analysis. I probably should have been clearer, I
was merely wondering if there was some slick introspection available in
scheme that would make this general and easy. My problem is trivial and the
cond solves it just fine. The macro you wrote above is very interesting.
Although for the reasons you pointed out I won't be using it I did get to
learn something. Thanks to all who replied.

Cheers,
 Peter
 --
 http://sjamaan.ath.cx
 --
 The process of preparing programs for a digital computer
  is especially attractive, not only because it can be economically
  and scientifically rewarding, but also because it can be an aesthetic
  experience much like composing poetry or music.
-- Donald Knuth

 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-03 Thread Peter Bex
On Sat, Mar 03, 2012 at 11:14:34AM -0700, Matt Welland wrote:
 It sounds like the answer I was looking for is that there is no scheme
 introspection that maps a procedure to the bound name.

It was part of my point that there is no the bound name, there
can be several.  What would this return?

(define x (lambda (y) (lambda () y)))
(name-of (x))

Or this:

(define (a b c) (apply b c))
(define gt )
(a (list gt))

There can be many things that are aliases for the same procedure.

 Thanks for the detailed analysis. I probably should have been clearer, I
 was merely wondering if there was some slick introspection available in
 scheme that would make this general and easy.

Contrary to popular belief and other Lisps, Scheme is really quite a
static language and lacks many of the more dynamic introspection
facilities of languages and systems like CLOS, Ruby or (shudder!) PHP.

This is generally a good thing, as it allows for pretty efficient
compilation and these introspection things only allow people to paint
themselves into a corner. Introspection allows cutting through the
language's abstraction barriers (which are there for a reason!) which
makes it too easy to write code riddled with assumptions about how the
other person's code is supposed to work.  Of course this kind of code
breaks the minute the other code makes internal changes (think
monkey-patching).

But the disadvantage is of course that it also means you can't use the
power of these facilities when they are called for (see also the lack of
general SLIME integration for Scheme).

 Although for the reasons you pointed out I won't be using it I did get to
 learn something.

I'm glad to hear that I've provided some useful insights!

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-03 Thread John Cowan
Peter Bex scripsit:

 Contrary to popular belief and other Lisps, Scheme is really quite a
 static language and lacks many of the more dynamic introspection
 facilities of languages and systems like CLOS, Ruby or (shudder!) PHP.

Don't forget Python, where even definitions are executable.  Though modern
Scheme is not as static as R4RS or ISLisp, where there is not even `eval`.
(Of course these languages are not static in the sense of static typing.)

-- 
John Cowanco...@ccil.orghttp://ccil.org/~cowan
The present impossibility of giving a scientific explanation is no proof
that there is no scientific explanation. The unexplained is not to be
identified with the unexplainable, and the strange and extraordinary
nature of a fact is not a justification for attributing it to powers
above nature.  --The Catholic Encyclopedia, s.v. telepathy (1913)

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-03 Thread Peter Bex
On Sat, Mar 03, 2012 at 02:06:56PM -0500, John Cowan wrote:
 Don't forget Python, where even definitions are executable.  Though modern
 Scheme is not as static as R4RS or ISLisp, where there is not even `eval`.
 (Of course these languages are not static in the sense of static typing.)

I don't have more than a passing familiarity with Python, so I had to
look up what you meant by definitions are executable, and I didn't
like what I found :)

Guide himself talks about this here:
http://python-history.blogspot.com/2009/03/how-everything-became-executable.html

PHP has this problem as well.  PHP even allows included
files and EVALed code to access local lexical variables in the
calling function.  I've often seen newbies in #scheme or #chicken
who were confused by this, and tried to graft similar functionality
on top of Scheme (which is utterly doomed to fail, of course)

And don't get me started on Javascript with its idiotic hoisting concept...

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-03 Thread John Cowan
Peter Bex scripsit:

 Guide himself talks about this here:
 http://python-history.blogspot.com/2009/03/how-everything-became-executable.html

Fascinating.  I'm working my way through the entire blog (fortunately
only 26 posts) even as we speak.

 PHP has this problem as well.  PHP even allows included files and
 EVALed code to access local lexical variables in the calling function.
 I've often seen newbies in #scheme or #chicken who were confused
 by this, and tried to graft similar functionality on top of Scheme
 (which is utterly doomed to fail, of course)

Whew.  I'm certainly glad I always stayed ten miles away from any
PHP code.

 And don't get me started on Javascript with its idiotic hoisting
 concept...

There are advantages to the scope of a declaration extending before
the declaration; it means you don't have to have special syntax to
forward-declare a name before you can use it in mutual recursion.
But basically I agree, especially for Scheme syntax declarations.
See The Tale of Professor Simpleton and Dr. Hardcase at
http://lists.r6rs.org/pipermail/r6rs-discuss/2009-September/005487.html .
-- 
John Cowanco...@ccil.org
Yakka foob mog.  Grug pubbawup zink wattoom gazork.  Chumble spuzz.
--Calvin, giving Newton's First Law in his own words

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] case vs. eq? - just curious ....

2012-03-02 Thread Matt Welland
I expected this to work:

(define (comp-text comp)
  (case comp
   ((=)=)
   (())
   (())
   ((=)  =)
   ((=)  =)
   (else unk)))

But had to convert to a cond with (eq? comp =) etc...

I thought case was supposed to use eq? to do the compare?

Thanks,

M a t t
-=-
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-02 Thread Kon Lovett

On Mar 2, 2012, at 3:52 PM, Matt Welland wrote:

 I expected this to work:
 
 (define (comp-text comp)
   (case comp
((=)=)
(())
(())
((=)  =)
((=)  =)
(else unk)))
 
 But had to convert to a cond with (eq? comp =) etc...

Are =, , etc variables? 'case' quotes the objects in each case. So comparing 
against symbols.

(##core#let
  ((tmp '=))
  (##core#if
(or (eqv? tmp '=))
(##core#begin =)
(##core#if
...

 
 I thought case was supposed to use eq? to do the compare?

eqv?

 
 Thanks,
 
 M a t t
 -=-
 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-02 Thread Jim Ursetto
eqv?, to be exact.  Your case statement works fine for me, with for example 
(comp-text '=).  (eq? comp =) compares against the value of the procedure =, 
whereas the case compares against the symbol =.  So you are doing two different 
comparisons.

You can use ,x (case ...) at the REPL to see what the case expands to.

Fake edit: Kon said this more succinctly than I did.
Jim

On Mar 2, 2012, at 5:52 PM, Matt Welland wrote:

 I expected this to work:
 
 (define (comp-text comp)
   (case comp
((=)=)
(())
(())
((=)  =)
((=)  =)
(else unk)))
 
 But had to convert to a cond with (eq? comp =) etc...
 
 I thought case was supposed to use eq? to do the compare?

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-02 Thread Matt Welland
On Fri, Mar 2, 2012 at 5:04 PM, Jim Ursetto zbignie...@gmail.com wrote:

 eqv?, to be exact.  Your case statement works fine for me, with for
 example (comp-text '=).  (eq? comp =) compares against the value of the *
 procedure* =, whereas the case compares against the symbol =.  So you are
 doing two different comparisons.


I'm trying to convert a comparison operator to the equivalent text. These
are not symbols. I think case treats the target list as if it was created
with a quote: '(). Thus things are all symbols in the list and the eqv?
returns false.

 (case  (() yup)(else nope))
nope
 (cond ((eqv?  ) yup)(else nope))
yup


The cond does what I need just fine, I just didn't understand why case
didn't also work.

Is there a more schemeish way to convert any of the operators to the text
representation?

(define gt )
(op-string gt)
 = 


 You can use *,x (case ...)* at the REPL to see what the case expands to.

 Fake edit: Kon said this more succinctly than I did.
 Jim

 On Mar 2, 2012, at 5:52 PM, Matt Welland wrote:

 I expected this to work:

 (define (comp-text comp)
   (case comp
((=)=)
(())
(())
((=)  =)
((=)  =)
(else unk)))

 But had to convert to a cond with (eq? comp =) etc...

 I thought case was supposed to use eq? to do the compare?



___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] case vs. eq? - just curious ....

2012-03-02 Thread Jim Ursetto

On Mar 2, 2012, at 7:57 PM, Matt Welland wrote:

 I'm trying to convert a comparison operator to the equivalent text. These are 
 not symbols. I think case treats the target list as if it was created with a 
 quote: '().

That's what case does.

You want `select`: http://api.call-cc.org/doc/chicken/special-forms/select .

 The cond does what I need just fine, I just didn't understand why case didn't 
 also work.

Expand it with ,x and you'll see.

Jim
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users