bugMIT/GNU Scheme - Bugs: bug #63568, Simple syntax-rules macro fails.

 
 

bug #63568: Simple syntax-rules macro fails.

Submitter:  Arthur A. Gleckler <aag>
Submitted:  Sat 24 Dec 2022 06:34:51 PM UTC
   
 
Category:  runtime Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Privacy:  Public
Assigned to:  cph Originator Name: 
Open/Closed:  Closed
Keywords: 
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 30 Dec 2022 02:39:53 AM UTC, comment #6: 

Yes, I meant y, thanks.

And I agree, "as many" is ambiguous, and I interpreted to mean "the same number of".  This is something for the editors to clarify; I'll send a message and CC you.

I agree that it is logical, and furthermore that it means there's no special treatment for non-ellipsis variables, as there is in my interpretation.

Chris Hanson <cph>
Group administrator
Thu 29 Dec 2022 11:32:46 AM UTC, comment #5: 

I assume you mean y, not x.  Seems like a mistake in the spec to say `as many' instead of `at least as many', assuming you mean R5RS or R7RS Sec. 4.3.2.  The relation of x to y seems much like the relation of y to z here; in principle this seems like the sensible expansion.

Taylor R. Campbell <riastradh>
Group Member
Thu 29 Dec 2022 02:04:46 AM UTC, comment #4: 

In your example, the variable x has one ellipsis in the pattern, but two in the template.  That's ruled out by the spec.

Chris Hanson <cph>
Group administrator
Thu 29 Dec 2022 12:01:41 AM UTC, comment #3: 

(let ()
  (define-syntax foo
    (syntax-rules ()
      ((foo (x (y z ...) ...))
       '(begin
          (add-foo! '(x y z))
          ... ...))))
  (foo (x (y1 z1a z1b) (y2 z2) (y3) (y4 z4a z4b z4c z4d))))
;Mismatched segment depth in template: (y)

I think this should expand to:

'(begin
   (add-foo! '(x y1 z1a))
   (add-foo! '(x y1 z1b))
   (add-foo! '(x y2 z2))
   (add-foo! '(x y4 z4a))
   (add-foo! '(x y4 z4b))
   (add-foo! '(x y4 z4c))
   (add-foo! '(x y4 z4d)))

Is there anything in the spec that rules this out?

Taylor R. Campbell <riastradh>
Group Member
Mon 26 Dec 2022 04:07:17 PM UTC, comment #2: 

Thanks.  That fixed it for me, as well as the bigger macro I started with, and is so far the only non-trivial issue I've had getting my code base to work with the new release.

Arthur A. Gleckler <aag>
Group Member
Mon 26 Dec 2022 11:25:08 AM UTC, comment #1: 

Didn't read the spec closely enough.  Vars bound in pattern segments are
supposed to be treated differently from those that aren't.  In particular,
non-segment vars are allowed inside template segments.

Chris Hanson <cph>
Group administrator
Sat 24 Dec 2022 06:34:51 PM UTC, original submission:  


(define-syntax define-foo
  (syntax-rules ()
    ((define-foo ((variable value ...)))
     (begin
       (add-foo! '(variable value))
       ...))))

;Mismatched segment depth in template: (variable)
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error>


I'm not sure what "segment depth" means, but I'm guessing that the problem is that value is subject to an ellipsis, but variable is not.  But I didn't think that it was a requirement that they be the same in that regard.

Chibi, Chicken, and Gauche Scheme all accept that definition.

Arthur A. Gleckler <aag>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by riastradh (Posted a comment)
  • -email is unavailable- added by cph (Posted a comment)
  • -email is unavailable- added by aag (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-12-26 cph CategoryNone runtime
        StatusNone Fixed
        Assigned toNone cph
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code