public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: Per Bothner <per@bothner.com>, kawa mailing list <kawa@sourceware.org>
Subject: Re: bug in kawa syntax transformer?
Date: Sun, 30 Jun 2024 22:56:58 +0200	[thread overview]
Message-ID: <CADEOadeRojxcvZuWp-=MDuOgcLF+6Ex_vD8xhu+hVM_9iW-iug@mail.gmail.com> (raw)
In-Reply-To: <CADEOade4AL3c51jfzWo9eWtC454MSsciFSccAmpAP7xzvCL7Rg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 7963 bytes --]

short answer:

there is a difference (that make crash and fail) between:
using (module-name "matrix") or (define-library (matrix) the r7rs style
,here the example (beginning of code only...):

(module-name "matrix")

;(define-library (matrix)

(export multiply-matrix-matrix
multiply-matrix-vector
matrix
matrix-v
create-matrix-by-function
dim-matrix
matrix-ref
matrix-set!
matrix-line-ref
matrix-line-set!
vector->matrix-column
matrix-column->vector

;;$ovrld-ht$
*
)

(import (Scheme+)
        (array))

;; first stage overloading
;(define orig* *)
(import (only (scheme base) (* orig*)))

(define-overload-existing-operator * orig*)


;; (matrix #(1 2 3))
;; matrix@4612b856


(define-simple-class matrix ()

  (v :: vector)

  ((*init* (vParam :: vector))
   (set! v vParam))

  )
....


long and truncated answer because i'm still investigating....

but it is better ,i was able to (load "program") without before (import
(Scheme+)) i will test moving all my modules with (module-name
"name-of-module") instead of the R7RS style... :

it is better, what is working and not:

(define-library (test-nfx) ; R7RS

  (import
 (kawa base)

 (operators-list)
 (n-arity)
 (infix-with-precedence-to-prefix)
 (nfx)
 )


  (define x ($nfx$ 3 * 5 + 2))
  (display x) (newline)

)

not working

but this works:

(require operators-list)
(require n-arity)
(require infix-with-precedence-to-prefix)
(require nfx)



  (define x ($nfx$ 3 * 5 + 2))
  (display x) (newline)


#|kawa:2|# (load "test-nfx-require.scm")
17


and also this:

#|kawa:1|# (load "test-nfx.scm")
17

in a program "loaded" with "load" this fails:

(require matrix)
(require Scheme+)

(require array)

;; first stage overloading
(import (only (kawa base) (+ orig+))) ; (* orig*)))


but this works:
(require Scheme+)
(require matrix)
(require array)

;; first stage overloading
(import (only (kawa base) (+ orig+))) ; (* orig*)))

so the order matters

but this fails in any order:
(import (Scheme+)
            (matrix)
            (array))

;; first stage overloading
(import (only (kawa base) (+ orig+))) ; (* orig*)))

but the modules works well as they are defined in R7RS:

;; use :

;;(import (Scheme+))
;; or :
;;(require Scheme+)


;;(module-name Scheme+)

(define-library (Scheme+) ; R7RS

  (import ;;(kawa base)
   ;;(only (scheme base) (do do-scheme)) ; only imports and rename do in
do-scheme
   (rename (kawa base) (do do-scheme)
              (if if-scheme)) ; standard imports and rename do in do-scheme
   (srfi 1) ; first ...
   (srfi 69); hash table
   (array)
   (for_next_step)
   (overload)

   (assignment)
   (bitwise)
   (block)
   (bracket-apply)
   (condx)
   (declare)
   (def)
   (exponential)
   (increment)
   (modulo)
   (nfx)
   (not-equal)
   (range)
   (repeat-until)
   (slice)
   (while-do)
   (if-then-else)

   ) ; end import




(export def
bracket-apply
;;$bracket-apply$next
: ;; $  see slice.scm
for
for-basic
for-next
for-basic/break
for-basic/break-cont
for/break-cont
for-each-in
in-range
reversed
<- ← :=
-> →
<+ ⥆ :+
+> ⥅
declare
$>
$+>
condx
<> ;; should not be compatible with 'cut' (srfi 26)
≠
**
<v v>
⇜ ⇝
repeat while do
if
%
<< >>
& ∣
$nfx$ ;;!*prec

$ovrld-ht$

define-overload-procedure
overload-procedure

define-overload-existing-procedure
overload-existing-procedure

define-overload-operator
overload-operator

define-overload-existing-operator
overload-existing-operator

define-overload-n-arity-operator
overload-n-arity-operator

define-overload-existing-n-arity-operator
overload-existing-n-arity-operator

;;overload-function

;;$ovrld-square-brackets-lst$

overload-square-brackets
;;find-getter-and-setter-for-overloaded-square-brackets
find-getter-for-overloaded-square-brackets
find-setter-for-overloaded-square-brackets

;;infix-operators-lst
;;set-infix-operators-lst!
;;replace-operator!
;;insert-operator!

) ; end export



) ; end module









On Sat, Jun 29, 2024 at 5:32 PM Damien Mattei <damien.mattei@gmail.com>
wrote:

> i find a way to make it run, i wanted to post the answer later....
>
> it works now.
>
> in summary the solution is:
>
> for a module test-foo that use module foo you have to:
>
> be at REPL and:
>
> (import (foo))
>
> (import (test-foo))
>
> and it is ok.
>
> but it is not the normal behavior , because as foo is already imported by
> test-foo the module should works without also importing foo in REPL
>
> example:
>
> test-nfx.scm:
>
> (define-library (test-nfx) ; R7RS
>
>   (import
>  (kawa base)
>
>  (operators-list)
>  (n-arity)
>  (infix-with-precedence-to-prefix)
>  (nfx))
>
>
>   (define x ($nfx$ 3 * 5 + 2))
>   (display x) (newline)
>
> )
>
> #|kawa:1|# (import (nfx))
> #|kawa:2|# ($nfx$ 3 * 5 + 2)
> 17
> #|kawa:3|# (import (test-nfx))
> 17
>
>
> another example:
>
> #|kawa:1|# (import (Scheme+))
> #|kawa:2|#
> #|kawa:3|# (bracket-apply #(1 2 3 4 5) 2)
> bracket-apply : #'parsed-args=(#<syntax#2463 list in #3590> 2)
> (bracket-apply #(1 2 3 4 5) 2)
> 3
> #|kawa:4|# ($nfx$ 3 * 5 + 2)
> 17
> #|kawa:5|# (exit)
>
> for a whole program that use Scheme+:
>
> #|kawa:1|# (import (Scheme+))
>
> #|kawa:2|# (load
> "exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa.scm")
>
> ################## NOT ##################
> *init* : nc=#(1 2 1)
> z=#(#(0) #(0 0) #(0))
> z̃=#(#(0) #(0 0) #(0))
> define-overload-existing-operator : proc =#<procedure *>
> define-overload-existing-operator : orig-proc =#<procedure *>
> M=#(matrix@3811464b matrix@5f0a5848)
> ᐁ=#(#(0) #(0 0) #(0))
> nbiter=5000
> exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa.scm:145:2:
> warning - no known slot 'apprentissage' in java.lang.Object
> 0
> 1000
> 2000
> 3000
> 4000
> exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa.scm:147:2:
> warning - no known slot 'test' in java.lang.Object
> Test des exemples :
> #(1) --> #(0.005218051056863006) : on attendait #(0)
> #(0) --> #(0.9937685906977904) : on attendait #(1)
> Error on examples=3.3029259361846465E-5
>
> ################## XOR ##################
> *init* : nc=#(2 8 1)
> z=#(#(0 0) #(0 0 0 0 0 0 0 0) #(0))
> z̃=#(#(0 0) #(0 0 0 0 0 0 0 0) #(0))
> M=#(matrix@7fb313e3 matrix@771ede0d)
> ᐁ=#(#(0 0) #(0 0 0 0 0 0 0 0) #(0))
> nbiter=250000
> exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa.scm:160:2:
> warning - no known slot 'apprentissage' in java.lang.Object
> exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa.scm:162:2:
> warning - no known slot 'test' in java.lang.Object
> Test des exemples :
> #(1 0) --> #(0.9869979600720541) : on attendait #(1)
> #(0 0) --> #(0.009586857552488845) : on attendait #(0)
> #(0 1) --> #(0.9875938547018659) : on attendait #(1)
> #(1 1) --> #(0.015785460599146515) : on attendait #(0)
> Error on examples=3.32027043752617E-4
>
> ################## SINE ##################
> *init* : nc=#(1 70 70 1)
>
> but perheaps there is a solution with playing with import/require,
> Kawa/R7RS  i will test any possible combinaison (? do not know the english
> term)
>
> the problem only happen with syntax transformer, if not , i would have
> noticed already......or someone else....
>
> Damien
>
> On Sat, Jun 29, 2024 at 4:17 PM Per Bothner <per@bothner.com> wrote:
>
>> Perhaps - or perhaps it depends on unspecified behavior.
>>
>> In any case, I think you're going to have to debug this on your own.
>>
>> On 6/29/24 2:03 AM, Damien Mattei via Kawa wrote:
>> > i'm sure it is a kawa bug because i ported all the code to Guile and it
>> > works perfectly.
>>
>> --
>>         --Per Bothner
>> per@bothner.com   http://per.bothner.com/
>>
>

  reply	other threads:[~2024-06-30 20:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-29  8:13 Damien Mattei
2024-06-29  9:03 ` Damien Mattei
2024-06-29 14:16   ` Per Bothner
2024-06-29 15:32     ` Damien Mattei
2024-06-30 20:56       ` Damien Mattei [this message]
2024-07-01  8:54       ` Damien Mattei
2024-07-01 13:44         ` 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

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

  git send-email \
    --in-reply-to='CADEOadeRojxcvZuWp-=MDuOgcLF+6Ex_vD8xhu+hVM_9iW-iug@mail.gmail.com' \
    --to=damien.mattei@gmail.com \
    --cc=kawa@sourceware.org \
    --cc=per@bothner.com \
    /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).