Re: [Chicken-users] matchable egg usage question

2011-01-28 Thread Alex Shinn
On Fri, Jan 28, 2011 at 2:21 PM, Alan Post  wrote:
> I'm trying to use the matchable egg to detect #!key parameters in
> functions I've constructed.  I have functions that accept multiple
> #!key parameters, and I'm not sure how to make the matchable egg
> match |(func ... mykey: myvalue ...)|.  That is, how to get the
> matchable egg to match two parameters anywhere in an input list.

Why not use Chicken's builtin #!key handling?

  (apply (lambda (#!key key1 key2)
;; code using key1 and key2
...)
 (list key1: val1 key2: val2))

> This is what I've got so far.  I am interested in whether the
> #!key paramater 'a' is set to #t:

OK, the original point of this style of pattern matching
was it was simple and fast - it does a simple linear
match against each possible pattern so is as fast as
using low-level destructuring and checking (faster if
the match library can eliminate common sub-patterns).

As soon as you introduce any ambiguity in how a
pattern can match the whole process becomes a
search algorithm, with backtracking in the general
case.  So whereas the pattern

  (a b c)

is constant time (O(m) in the pattern size),

  (a b c ...)

is linear (O(n) in the input size), which is fine, but

  (a b c ... d ...)

is O(n^2) in the input size depending on where
you choose to split between c and d.  And

  (a b c ... d ... e ...)

is O(n^3), etc.

Most of the time when you want to use this sort
of pattern, you don't want backtracking - you want
c to match as many elements as it can and then
"commit," and take the rest of the list as d.  So if
the match doesn't let you express the expensive
patterns, you have to iterate over one c at a time:

  (let lp ((ls ls) (c-ls '())
(match ls
  ((c . rest) (lp (cdr ls) (cons c c-ls)))
  (else
   ;; match d's in remaining ls
   ...)))

This is O(n), and is the same sort of idiom many
complex syntax-rules libraries use.

So by deliberately limiting match we force people
to write faster code.  At the same time, it's more
verbose code - if you really want a match as powerful
as prolog you could implement it and deal with the
fact that it can be very slow in some cases.  And in
that case you will eventually need to add a way to
explicitly commit matches (i.e. "cut" in prolog) for
decent performance.

[I'm not completely consistent in this, though,
because the tree patterns I added do in fact
require more complex searching and backtracking.
But tree searches require this in general.]

-- 
Alex

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


Re: [Chicken-users] Re: matchable egg ticket #487

2011-01-28 Thread Alan Post
On Sat, Jan 29, 2011 at 10:52:15AM +0900, Alex Shinn wrote:
> On Fri, Jan 28, 2011 at 12:15 AM, Alan Post  
> wrote:
> > I'm only going to get more demanding out of what I'd like match to
> > do, I would like the latest version.
> 
> I've updated matchable from the latest upstream,
> which includes the fix.
> 

Thank you Alex.  I've updated my copy of the matchable egg, removed
the workaround I was using to avoid triggering the bug, and after
that change my regression tests all pass.

-Alan
-- 
.i ko djuno fi le do sevzi

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


Re: [Chicken-users] Re: matchable egg ticket #487

2011-01-28 Thread Alex Shinn
On Fri, Jan 28, 2011 at 12:15 AM, Alan Post  wrote:
> I'm only going to get more demanding out of what I'd like match to
> do, I would like the latest version.

I've updated matchable from the latest upstream,
which includes the fix.

-- 
Alex

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


[Chicken-users] syntax-case?

2011-01-28 Thread Joe Python
Is there a egg for syntax-case macros in Chicken 4?

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


[Chicken-users] Re: matchable egg usage question

2011-01-28 Thread Alan Post
On Thu, Jan 27, 2011 at 10:21:05PM -0700, Alan Post wrote:
> I'm trying to use the matchable egg to detect #!key parameters in
> functions I've constructed.  I have functions that accept multiple
> #!key parameters, and I'm not sure how to make the matchable egg
> match |(func ... mykey: myvalue ...)|.  That is, how to get the
> matchable egg to match two parameters anywhere in an input list.
> 
> This is what I've got so far.  I am interested in whether the
> #!key paramater 'a' is set to #t:
> 
>   (use matchable)
> 
>   (pretty-print (map
> (match-lambda
>   ((_ 'a: #t . _) '(0 #t))
>   ((_ ... 'a: #t) '(1 #t))
>   (_  #f))
> '((foo)
>   (foo bar)
>   (foo a: #f)
>   (foo a: #f b: #t)
>   (foo a: #f b: #t c: #t)
>   (foo a: #f c: #t b: #t)
>   (foo b: #t a: #f c: #t)
>   (foo b: #t c: #t a: #f)
>   (foo a: #t)
>   (foo a: #t b: #t)
>   (foo a: #t b: #t c: #t)
>   (foo a: #t c: #t b: #t)
>   (foo b: #t a: #t c: #t)
>   (foo b: #t c: #t a: #t
>   (exit)
> 
> This works for every case except when the #!key I want to match
> appears in the middle of a list of arguments, as happens in the
> second-to-last case I'm trying to match.
> 
> Is there a way to make match work in this case?  What pattern
> should I add to match values anywhere in the list, not just the
> front and end?
> 

I've solved my problem by matching every sublist of my argument
list until I find the pattern I'm looking for:

  (use matchable)
  (use srfi-1)

  (define (key-match? pat r)
(or r (match pat
(`(a: #t . ,_) #t)
(_ #f

  (pretty-print (map
(match-lambda
  ((_ . args) (pair-fold key-match? #f args))
  (_ #f))
'((foo)
  (foo bar)
  (foo a: #f)
  (foo a: #f b: #t)
  (foo a: #f b: #t c: #t)
  (foo a: #f c: #t b: #t)
  (foo b: #t a: #f c: #t)
  (foo b: #t c: #t a: #f)
  (foo a: #t)
  (foo a: #t b: #t)
  (foo a: #t b: #t c: #t)
  (foo a: #t c: #t b: #t)
  (foo b: #t a: #t c: #t)
  (foo b: #t c: #t a: #t
  (exit)

(The match-lambda here is wordier in my real example, I know it is
pointless in this example.)

-Alan
-- 
.i ko djuno fi le do sevzi

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


[Chicken-users] New python/chicken

2011-01-28 Thread David Dreisigmeyer
This is an improved version of a Chicken REPL embedded in a Python
REPL.  Variable passing between Python and Chicken is automatic but
could probably still use some work.  It should be possible to use the
Chicken REPL without the need for any special command to interact with
Python.  If you want to run one command in Chicken and exit back to
Python you should use:

>>> py_var = c_(once = 1)

Otherwise you'll stay in the Chicken REPL until issuing a ,q or (exit) command.

Let me know if you notice anything wrong, or would like something else
incorporated.  I'm planning on starting to wrap this up as a Python
egg soon.

-Dave


scythians.tgz
Description: GNU Zip compressed data
___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Need help on sxpath/txpath

2011-01-28 Thread Peter Bex
On Sat, Jan 29, 2011 at 12:11:26AM +0900, Daishi Kato wrote:
> > It probably is not a chicken-specific problem because the sxpath
> > egg includes an unmodified copy of SSAX.
> 
> Looked at:
> diff -rw release/3/sxml-tools/sxml-tools/ release/4/sxpath/trunk/sxml-tools/
> 
> but, I'm not sure is there's such a big difference.
> Furthermode, it's hardly understandable that the newer version is incorrect.
> 
> I don't know what to do... Confirm if it's really a bug against XPath spec?

I suck at xpath so I have no idea.  You could try the SSAX mailinglist...

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
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Need help on sxpath/txpath

2011-01-28 Thread Daishi Kato
At Fri, 28 Jan 2011 15:34:09 +0100,
Peter Bex wrote:
> 
> On Fri, Jan 28, 2011 at 11:27:26PM +0900, Daishi Kato wrote:
> > Hi,
> > 
> > I digged into the problem a little more and found something.
> > 
> > In 4.6.0, this is somewhat working:
> > #;24> ((sxpath "//table/tr[td[a[contains(href,'&abc=123&')]]]") 
> > (html->sxml " > href=\"/xxx/yyy/?zzz&abc=123&\">yyy"))
> > ((tr (td (a (@ (href "/xxx/yyy/?zzz&abc=123&")) "yyy"
> > 
> > So, I replaced @href with href.
> > Is it correct? Maybe not.
> > I assume the sxpath egg is incorrect.
> > 
> > Can anybody tell if this is a chicken-specific problem, or
> > of sxml-tools at sourceforge?
> 
> It probably is not a chicken-specific problem because the sxpath
> egg includes an unmodified copy of SSAX.

Looked at:
diff -rw release/3/sxml-tools/sxml-tools/ release/4/sxpath/trunk/sxml-tools/

but, I'm not sure is there's such a big difference.
Furthermode, it's hardly understandable that the newer version is incorrect.

I don't know what to do... Confirm if it's really a bug against XPath spec?

Best,
Daishi


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


Re: [Chicken-users] Need help on sxpath/txpath

2011-01-28 Thread Peter Bex
On Fri, Jan 28, 2011 at 11:27:26PM +0900, Daishi Kato wrote:
> Hi,
> 
> I digged into the problem a little more and found something.
> 
> In 4.6.0, this is somewhat working:
> #;24> ((sxpath "//table/tr[td[a[contains(href,'&abc=123&')]]]") 
> (html->sxml " href=\"/xxx/yyy/?zzz&abc=123&\">yyy"))
> ((tr (td (a (@ (href "/xxx/yyy/?zzz&abc=123&")) "yyy"
> 
> So, I replaced @href with href.
> Is it correct? Maybe not.
> I assume the sxpath egg is incorrect.
> 
> Can anybody tell if this is a chicken-specific problem, or
> of sxml-tools at sourceforge?

It probably is not a chicken-specific problem because the sxpath
egg includes an unmodified copy of SSAX.

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
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Need help on sxpath/txpath

2011-01-28 Thread Daishi Kato
Hi,

I digged into the problem a little more and found something.

In 4.6.0, this is somewhat working:
#;24> ((sxpath "//table/tr[td[a[contains(href,'&abc=123&')]]]") 
(html->sxml "yyy"))
((tr (td (a (@ (href "/xxx/yyy/?zzz&abc=123&")) "yyy"

So, I replaced @href with href.
Is it correct? Maybe not.
I assume the sxpath egg is incorrect.

Can anybody tell if this is a chicken-specific problem, or
of sxml-tools at sourceforge?

Best,
Daishi

At Sun, 16 Jan 2011 22:32:23 +0900,
Daishi Kato wrote:
> 
> Here you go. --daishi
> 
> CHICKEN
> (c)2008-2010 The Chicken Team
> (c)2000-2007 Felix L. Winkelmann
> Version 4.6.0
> linux-unix-gnu-x86 [ manyargs dload ptables ]
> compiled 2011-01-11 on spirits (Linux)
> 
> #;1> (use sxpath htmlprag utils)
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/sxpath.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/chicken.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/scheme.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/data-structures.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/srfi-1.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/srfi-13.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/sxpath-lolevel.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/extras.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/ports.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/txpath.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/htmlprag.import.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/sxpath.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/sxpath-lolevel.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/txpath.so ...
> ; loading /usr/local/chicken-4.6.0/lib/chicken/5/htmlprag.so ...
> ; loading library utils ...
> #;2> ((sxpath "//table/tr[td[a[contains(@href,'&abc=123&')]]]") 
> (html->sxml " href=\"/xxx/yyy/?zzz&abc=123&\">yyy"))
> ()
> #;3>
> 
> 
> CHICKEN
> (c)2008 The Chicken Team
> (c)2000-2007 Felix L. Winkelmann
> Version 3.2.0 - linux-unix-gnu-x86  [ manyargs dload ptables applyhook ]
> SVN rev. 10664  compiled 2008-05-28 on spirits (Linux)
> 
> #;1> (use sxml-tools htmlprag utils)
> ; loading /usr/local/chicken-3.2.0/lib/chicken/3/sxml-tools.so ...
> ; loading /usr/local/chicken-3.2.0/lib/chicken/3/htmlprag.so ...
> ; loading library utils ...
> #;2> ((sxpath "//table/tr[td[a[contains(@href,'&abc=123&')]]]") 
> (html->sxml " href=\"/xxx/yyy/?zzz&abc=123&\">yyy"))
> ((tr (td (a (@ (href "/xxx/yyy/?zzz&abc=123&")) "yyy"
> #;3>
> 
> 
> At Sun, 16 Jan 2011 13:27:41 +0100,
> Peter Bex wrote:
> > 
> > On Sun, Jan 16, 2011 at 03:49:41PM +0900, Daishi Kato wrote:
> > > Hi,
> > > 
> > > I'm porting one of my projects from chicken-3.2.0 to chicken-4.6.0.
> > > (And thus found a bug in http-client.)
> > > 
> > > It seems like the previous sxpath doesn't work on the new one.
> > > Could anybody help how I can fix this?
> > > 
> > > The sxpath worked on chicken-3.2.0 is something like the following:
> > > 
> > > ((sxpath "//table/tr[td[a[contains(@href,'&abc=123&')]]]") x)
> > > 
> > > On 3.2.0 I used the sxml-tools egg and the sxpath egg on 4.6.0
> > 
> > What is the error you get?  What is the content you run this
> > expression on?  Can you simplify it to a simple testcase?
> > 
> > My gut feeling is that the & is maybe wrong.  Did you try just '&'?
> > 
> > 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
> > http://lists.nongnu.org/mailman/listinfo/chicken-users
> > 
> > **
> >  XREA.COM -Free Web Hosting-
> >  http://www.xrea.com/
> > **

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


Re: [Chicken-users] chicken slime REPL message

2011-01-28 Thread Joe Python
Ah!
I was expecting something in the lines of the clojure repl where it echoes
the function name and its namespace it lives in.
user=> (defn hello []
(println "hi"))
#'user/hello



On Thu, Jan 27, 2011 at 11:54 AM, David Krentzlin
wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Hi,
>
> yes, this is normal behaviour. What you see is the printable
> representation of the return value of the define form.
> As you may have guessed, it has none, so it prints #.
> Try it with a form that does actually produce a value.
>
>
> cheers david
>
>
> On 27.01.2011 14:40, Joe Python wrote:
> > Is it normal behaviour to get the '#' message.
> >
> > ; SLIME 2010-01-03
> > CSI> (define (hello)
> >  (display "Hi"))
> > #
> > CSI>
> >
> >
> >
> > ___
> > Chicken-users mailing list
> > Chicken-users@nongnu.org
> > http://lists.nongnu.org/mailman/listinfo/chicken-users
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQIcBAEBAgAGBQJNQaMuAAoJEPZusy+CqjZ2KMAQAKMCO6mAlElo+ekRYye2dNWM
> 5btGfStkj19jqKjiVSOYMvQMJEPy1op8vmT5Zm5Wolqya0rW7EdmjzwduXp/2SY4
> E51/y5+dza/e9MisIQPYmkkP846/UDcdUvhVBh2lZWdpfFE0S1tX/KUMah6B10KO
> dC3AfI4fJY9dtnF4Pe05ZZjSPhTznHClPc9PS34vD7yvE2K8T0zR5U4JNcMVof47
> zP+SyBwGSr+1CTS4B1SwhpZWGter8uX9z/O9U84CfKF2T1Ci/fPlYO2mv3M/u/e8
> p1MlFLYcnlcl2SGVRwUF2vy7g3e7rN3QRJ85tQGrU+Pmb0BeqXWyWoUQiQ/PD/4w
> QaPmKT4KOqGVJ8R6mMVg65JKV5C4zftXIICZHBWhnv0Vs+1jx8rbvaJQ6DcR+CCX
> FEbKK0GMuVxhtwJ3TnSIFXF+ZRTViH5zqinaSchXmrPuUc4ZSJxqWlgEYd7WqsG2
> 5lg2KId/RrLJmRGYyRfllBrrHd72YnaAahijXEY+Z2A48TCNA2FmBdRYWFUy0Lpa
> P69G9R+2UnjBT9sPRpNzy+P8l0Z5XIz70b0vg9e4UjA+m2s9DHGDBL5KeX78rE6w
> yKZE1mc3vormHbBgX8/IlOw/eF3XSsOv4ET8g/GMPXoULqzCcgQbytAtt0pOzzzZ
> 6KmLpFcf4eqTTgZVBx+G
> =+49l
> -END PGP SIGNATURE-
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users