public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Recursive define-syntax
@ 2021-09-26 12:08 Philippe de Rochambeau
  2021-09-26 21:04 ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-26 12:08 UTC (permalink / raw)
  To: kawa


Hello,

the following procedure, excerpted from « A Pamphlet Against R » 

(define (dim m)
 (match m
   ((first . rest)
     `(,(length m) . ,(dim first)))
    (_
      '())))

… causes Kawa to display the following error message:

/dev/tty:6:5: unrecognized pattern operator first


I tried rewriting the dim procedure using define-syntax:


(define m0 '((1 2 3 4)(0 4 5 8)(0 0 7 6)))

(define-syntax dim 
    (lambda (m)
        (syntax-case m ()
            ((_ frst . rst)
                #`(#,(length m) . #,(dim first)))
            (_
                '()))))
    
…but to no avail:

matrix1.scm:7:17: duplicated pattern variable frst
matrix1.scm:7:13: duplicated pattern variable rst
matrix1.scm:7:17: duplicated pattern variable frst
matrix1.scm:7:13: duplicated pattern variable rst
…

Are recursive « syntaxes »  not possible in Kawa?

Many thanks.

Philippe

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

* Re: Recursive define-syntax
  2021-09-26 12:08 Recursive define-syntax Philippe de Rochambeau
@ 2021-09-26 21:04 ` Per Bothner
  2021-09-27  5:05   ` Philippe de Rochambeau
  0 siblings, 1 reply; 5+ messages in thread
From: Per Bothner @ 2021-09-26 21:04 UTC (permalink / raw)
  To: Philippe de Rochambeau, kawa



On 9/26/21 05:08, Philippe de Rochambeau via Kawa wrote:
> 
> Hello,
> 
> the following procedure, excerpted from « A Pamphlet Against R »
> 
> (define (dim m)
>   (match m
>     ((first . rest)
>       `(,(length m) . ,(dim first)))
>      (_
>        '())))
> 
> … causes Kawa to display the following error message:
> 
> /dev/tty:6:5: unrecognized pattern operator first

There is no standard Scheme 'match' syntax - there are a
number of different and incompatible extensions.  « A Pamphlet Against R »
uses the Guile language, which is quite different frm Kawa.

Specifically, the Kawa "pattern" syntax is quite limited - it
is mainly a proof of concept - a test of the basic framework.

Thar said, this seems to work:

(define (dim m)
  (match m
    ([first rest ...]
      `(,(length m) . ,(dim first)))
     (_
      '())))

(dim m0) => (3 4)

> Are recursive « syntaxes »  not possible in Kawa?

Before you ask that question, you should try some code that
works on at least one other (preferable two) Scheme implementations.
If you have example code that works on other Scheme implementation(s)
and does not depend on an implementation-specific extension, but
not on Kawa - then we can discuss whether there is a Kawa bug or limitation.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

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

* Re: Recursive define-syntax
  2021-09-26 21:04 ` Per Bothner
@ 2021-09-27  5:05   ` Philippe de Rochambeau
  2021-09-27  5:31     ` Philippe de Rochambeau
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-27  5:05 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

Hi Per,
Thank you for your feedback.
The code works on LispKit (cf. https://github.com/objecthub/swift-lispkit) which is based on R7RS. But if it doesn’t work in Kawa, it doesn’t really matter.

#|
Pamphlet, p. 52
|#
(import (lispkit match))
(import (srfi 48))

(define (dim m)
 (match m
   ((first . rest)
     `(,(length m) . ,(dim first)))
    (_
      '())))

Cheers,
Philippe

> Le 26 sept. 2021 à 23:04, Per Bothner <per@bothner.com> a écrit :
> 
> 
> 
>> On 9/26/21 05:08, Philippe de Rochambeau via Kawa wrote:
>> Hello,
>> the following procedure, excerpted from « A Pamphlet Against R »
>> (define (dim m)
>>  (match m
>>    ((first . rest)
>>      `(,(length m) . ,(dim first)))
>>     (_
>>       '())))
>> … causes Kawa to display the following error message:
>> /dev/tty:6:5: unrecognized pattern operator first
> 
> There is no standard Scheme 'match' syntax - there are a
> number of different and incompatible extensions.  « A Pamphlet Against R »
> uses the Guile language, which is quite different frm Kawa.
> 
> Specifically, the Kawa "pattern" syntax is quite limited - it
> is mainly a proof of concept - a test of the basic framework.
> 
> Thar said, this seems to work:
> 
> (define (dim m)
> (match m
>   ([first rest ...]
>     `(,(length m) . ,(dim first)))
>    (_
>     '())))
> 
> (dim m0) => (3 4)
> 
>> Are recursive « syntaxes »  not possible in Kawa?
> 
> Before you ask that question, you should try some code that
> works on at least one other (preferable two) Scheme implementations.
> If you have example code that works on other Scheme implementation(s)
> and does not depend on an implementation-specific extension, but
> not on Kawa - then we can discuss whether there is a Kawa bug or limitation.
> -- 
>    --Per Bothner
> per@bothner.com   http://per.bothner.com/

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

* Re: Recursive define-syntax
  2021-09-27  5:05   ` Philippe de Rochambeau
@ 2021-09-27  5:31     ` Philippe de Rochambeau
  2021-09-27 16:06       ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-27  5:31 UTC (permalink / raw)
  To: Philippe de Rochambeau via Kawa

BTW, Kawa is an amazing piece of software and it is my favorite JVM-based programming language.

Philippe

> Le 27 sept. 2021 à 07 a écrit :
> 
> Hi Per,
> Thank you for your feedback.
> The code works on LispKit (cf. https://github.com/objecthub/swift-lispkit) which is based on R7RS. But if it doesn’t work in Kawa, it doesn’t really matter.
> 
> #|
> Pamphlet, p. 52
> |#
> (import (lispkit match))
> (import (srfi 48))
> 
> (define (dim m)
>  (match m
>    ((first . rest)
>      `(,(length m) . ,(dim first)))
>     (_
>       '())))
> 
> Cheers,
> Philippe
> 
>>> Le 26 sept. 2021 à 23:04, Per Bothner <per@bothner.com> a écrit :
>>> 
>> 
>> 
>>> On 9/26/21 05:08, Philippe de Rochambeau via Kawa wrote:
>>> Hello,
>>> the following procedure, excerpted from « A Pamphlet Against R »
>>> (define (dim m)
>>>  (match m
>>>    ((first . rest)
>>>      `(,(length m) . ,(dim first)))
>>>     (_
>>>       '())))
>>> … causes Kawa to display the following error message:
>>> /dev/tty:6:5: unrecognized pattern operator first
>> 
>> There is no standard Scheme 'match' syntax - there are a
>> number of different and incompatible extensions.  « A Pamphlet Against R »
>> uses the Guile language, which is quite different frm Kawa.
>> 
>> Specifically, the Kawa "pattern" syntax is quite limited - it
>> is mainly a proof of concept - a test of the basic framework.
>> 
>> Thar said, this seems to work:
>> 
>> (define (dim m)
>> (match m
>>   ([first rest ...]
>>     `(,(length m) . ,(dim first)))
>>    (_
>>     '())))
>> 
>> (dim m0) => (3 4)
>> 
>>> Are recursive « syntaxes »  not possible in Kawa?
>> 
>> Before you ask that question, you should try some code that
>> works on at least one other (preferable two) Scheme implementations.
>> If you have example code that works on other Scheme implementation(s)
>> and does not depend on an implementation-specific extension, but
>> not on Kawa - then we can discuss whether there is a Kawa bug or limitation.
>> -- 
>>    --Per Bothner
>> per@bothner.com   http://per.bothner.com/

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

* Re: Recursive define-syntax
  2021-09-27  5:31     ` Philippe de Rochambeau
@ 2021-09-27 16:06       ` Per Bothner
  0 siblings, 0 replies; 5+ messages in thread
From: Per Bothner @ 2021-09-27 16:06 UTC (permalink / raw)
  To: Philippe de Rochambeau, Philippe de Rochambeau via Kawa

On 9/26/21 22:31, Philippe de Rochambeau wrote:
> BTW, Kawa is an amazing piece of software and it is my favorite JVM-based programming language.

Compliments are always welcome!

Now tell all your friends ...
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

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

end of thread, other threads:[~2021-09-27 16:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26 12:08 Recursive define-syntax Philippe de Rochambeau
2021-09-26 21:04 ` Per Bothner
2021-09-27  5:05   ` Philippe de Rochambeau
2021-09-27  5:31     ` Philippe de Rochambeau
2021-09-27 16:06       ` Per Bothner

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