unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: adding #' syntax and my cloned macro no more works like original....
Date: Thu, 9 May 2024 11:07:59 +0200	[thread overview]
Message-ID: <CADEOadeyq6NeZAtTCdktZZBxtm-2PpHE2R90tULkpz4CRargig@mail.gmail.com> (raw)

hello,

i having a little horrific bug in one of my macro. In fact i have 2 macro :
<- that do all the job and another alias ←

till now the ← acted as a perfect clone of <- wihtout having all the code,
being defined as:

(define-syntax ← ;; under Linux this symbol can be typed with the
   ;; combination of keys: Ctrl-Shift-u 2190 where 2190 is the unicode of
left arrow

   (syntax-rules ()

     ((_ var ...) (<- var ...))))

but now that i added a few 'syntax' to <- , i have errors using ← , some
bindings become unbinded:

error is sort of :

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: lin

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,q

appearing in:

{iepi[{lin + 1} 0] ← vct-prime-implicants[lin]}

if i replace it with:

{iepi[{lin + 1} 0] <- vct-prime-implicants[lin]}

all works again.

backtrace is of no help, sort of:
scheme@(guile-user) [1]> ,bt
In /Users/mattei/library-FunctProg/guile/logiki+.scm:
  2848:18  5 (_ #<continuation 1073b2380>)
   743:23  4 (infix-symb-min-dnf _)
  1777:41  3 (minimal-dnf _)
  2707:38  2 (_ _)
  2546:18  1 (identify-essential-prime-implicants _ _)
In ice-9/boot-9.scm:
  1685:16  0 (raise-exception _ #:continuable? _)

i know it is a macro problem, not in procedures,and it is since i added
some #' syntax to optimize code...

a solution would be to duplicate all the code from <- into ← but this is
stupid.

how can i change ← to act perfectly as <- ?

i'm afraid to post it but i think i must post the code of <- to get any
help about that:

;; {s <+ (string-append "abcdefgh")};; "abcdefgh";; > {s[2 * 3 - 4 $ 2
* 3 + 1 $ 2 * 4 - 6] <- "0000"};; "ab0d0f0h"
;; $bracket-apply$ is from SRFI 105  bracket-apply is an argument of
the macro(define-syntax <-

  (lambda (stx)

    (syntax-case stx ()


      ;; silly case
      ((_ ( ) expr)
       #'(void)) ;; void is not portable ;'())

      ;; one value in values !
      ;; > {(x) <- (values 7)}
      ;; > x
      ;; 7
      ((_ (var) expr)

       #'(set!-values-plus (var) expr))



      ;; example: {a[4] <- 7}
      ;; $bracket-apply$ is from SRFI 105  bracket-apply is an
argument of the macro

      ((_ (brket-applynext container index ...) expr)  ; possible to
have NO index :
					; minimal form is (_ (brket-applynext container) expr)

       ;; We will let the second $bracket-apply$ be executed and
forbid the execution of first $bracket-apply$.
       (cond ((equal? (quote $bracket-apply$next) (syntax->datum
#'brket-applynext))  ;; already parsed and optimised by parser

	      #'(assignmentnext container expr index  ...)) ; possible to have NO index


	     ;; integrated curly-infix of guile (no parsing) at REPL
	     ((equal? (quote $bracket-apply$) (syntax->datum #'brket-applynext))

	      (display "<- : (syntax->datum #'(index ...)) = ") (display
(syntax->datum #'(index ...))) (newline)
	      (display "<- : (number? (car (syntax->datum #'(index ...)))) =
") (display (number? (car (syntax->datum #'(index ...))))) (newline)
	
	      ;; parse arguments at posteriori here:
	      (with-syntax ((parsed-args (datum->syntax stx ; #f
							(cons #'list
							      (optimizer-parse-square-brackets-arguments-lister
(syntax->datum #'(index ...)))))))
			   (display "<- : #'parsed-args=") (display #'parsed-args) (newline)
			   (display "<- :  (syntax->datum #'parsed-args)=") (display
(syntax->datum #'parsed-args)) (newline)
	
			   ;;(case (length (syntax->datum #'(index ...)))
			   (case (length (cdr (syntax->datum #'parsed-args)))

			     ;; 0 argument in []
			     ;; T[]
			     ;; {v[] <- #(1 2 3)}
			     ;; > v
			     ;;'#(1 2 3)
			     ((0)
			      #'(assignment-argument-0 container expr))  ; possible to have NO index

			     ;; 1 argument in [ ]
			     ;; T[index]
			     ((1)
			      #'(assignment-argument-1 container
						       (first parsed-args)
						       expr))

			     ;; 2 arguments in [ ]
			     ;; ex: T[i1 :] , T[: i2], T[i1 i2] , T[: :]
			     ;; {#(1 2 3 4 5)[inexact->exact(floor(2.7)) :]}
			     ;; '#(3 4 5)
			     ((2)
			      #'(assignment-argument-2 container
						       (first parsed-args)
						       (second parsed-args)
						       expr))

			     ;; 3 arguments in [ ]
			     ;; T[i1 : i2] , T[i1 i2 i3] , T[: : s]
			     ((3)
			      #'(assignment-argument-3 container					
						       (first parsed-args)
						       (second parsed-args)
						       (third parsed-args)
						       expr))
			
			     ;; 4 arguments in [ ]
			     ;; T[: i2 : s] , T[i1 : : s] , T[i1 : i3 :] , T[i1 i2 i3 i4]
			     ((4)
			      #'(assignment-argument-4 container
						       (first parsed-args)
						       (second parsed-args)
						       (third parsed-args)
						       (fourth parsed-args)
						       expr))

			     ;; 5 arguments in [ ]
			     ;; T[i1 : i3 : s] , T[i1 i2 i3 i4 i5]
			     ((5)
			      #'(assignment-argument-5 container
						       (first parsed-args)
						       (second parsed-args)
						       (third parsed-args)
						       (fourth parsed-args)
						       (fifth parsed-args)
						       expr))

			     ;; more than 5 arguments in [ ]
			     ;; T[i1 i2 i3 i4 i5 i6 ...]
			     (else ; case
			      #'(assignment-argument-6-and-more container parsed-args expr)))))

	     (else ; cond
	      #'(set!-values-plus (brket-applynext container index ...)
expr)))) ; warning: the argument's names does not match the use



      ;;(<- x 5)
      ((_ var expr)

       #'(set! var expr))


      ;; (declare x y z t)
      ;; {x <- y <- z <- t <- 7}
      ;; 7
      ;; (list x y z t)
      ;; (7 7 7 7)

      ;; > (require srfi/25)
      ;; > {I <- (make-array (shape 0 4 0 4))}
      ;; #<array:srfi-9-record-type-descriptor>
      ;; > {I[0 0] <- I[1 1] <- I[2 2] <- I[3 3] <- 1}
      ;; 1
      ;; > {I[0 0]}
      ;; 1
      ;; > {I[0 1]}
      ;; 0
      ;; > I
      ;; #<array:srfi-9-record-type-descriptor>

      ;; > (declare a b c d)
      ;; > {(a b) <- (c d) <- (values 5 7)}
      ;; > a
      ;; 5
      ;; > b
      ;; 7
      ;; > c
      ;; 5
      ;; > d
      ;; 7

      ;; without declare:
      ;; > {(a b) <- (c d) <- (values 5 7)}
      ;; > (list a b c d)
      ;; '(5 7 5 7)
      ((_ var var1 ... expr)


       #'(begin ;; i do not do what the syntax says (assignation not
in the good order) but it gives the same result
	   ;;(display "<- : case (_ var var1 ... expr)") (newline)
	
	   (define return-values-of-expr (create-return-values expr))
	   (<- var (return-values-of-expr))
	   ;;(display "<- : case : passed (<- var expr)") (newline)
	   ;;(display "<- : case : var=") (display var) (newline)
	
	   (<- var1 (return-values-of-expr))
	   ...))


      )))




Best regards,
Damien


             reply	other threads:[~2024-05-09  9:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09  9:07 Damien Mattei [this message]
2024-05-09  9:16 ` adding #' syntax and my cloned macro no more works like original Maxime Devos
2024-05-09 22:04   ` Damien Mattei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADEOadeyq6NeZAtTCdktZZBxtm-2PpHE2R90tULkpz4CRargig@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).