From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 0389E3858D1E for ; Wed, 1 Nov 2023 16:11:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0389E3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0389E3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698855100; cv=none; b=ESPgrQv/ZSxvxyFu7pO2vz+nzJa1SD6pTPkcqhBg4oJe27atDCJVAcwNgxB0JdwKVXGrSS+gIieA+FET4Qj0UkgT1xhuMFuqIFOsL64eyLuGUDbKvH7E/WTu2RnrulWRHXQvf+Q2QbnlMNY54P6v4TX6n9p/cQb2JOpPqiHUlX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698855100; c=relaxed/simple; bh=UhktLZ30gkgBe41uQi8Cr7kMIOE0in2dxej783Kt48w=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=om4Y8AhuTXiuU6tswfAhkOAHRAYNrs5BCGB+1gAfLUv9M4wpUeC17/+ff+bpECfdgPbAN0yFL4uCmrWhjkT4sHbYoOzoG1byB8oYSzfSaupZhaDS9RdfXTCt0hmD3B247mfkXcYhzYbccjO6DtdMU2AouBbfCg7TDonZKviRvbc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-543923af573so1907569a12.0 for ; Wed, 01 Nov 2023 09:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698855095; x=1699459895; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zP6LR7T+O35sqUMSflFDtlxfU/ctVpEbD7scJuaxrFo=; b=guMajPEN7nRf8RZAt05axT//wLH+Og27TlxS237CY4jufgBK0pN4PdVCWSM0tP1gCE JChO3XpV6vc0qh8c33OHwyWVdpDAF+URqXk6m6vhAzgS4GRxSAGI4oOrBu7ObjF+q/Vw koeslpX2qodJLSDITpkyzMA706qPDZfSgqWFy5hBtBYQMMYagXAnmHP/8Hfu98MNGEBH JpJKvBTpm+H5m3pp8qigvna4GcPlWSlOX0GHgGLF5jfDTmEw7wjSpajXoJAcbzfaiF38 MrxSvaQVV7nA82qdrA4dac2+eqba1endH2lXeNaeC4gWDzK6U2QCVZkL4yIWxAIOXWjj oysA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698855095; x=1699459895; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zP6LR7T+O35sqUMSflFDtlxfU/ctVpEbD7scJuaxrFo=; b=BJjcHu6uwVqd+Vy56Q7TTkdMWhhF+fnRgFLCShdmfyNiA1GM9YiDtujnPC9EQ4/o0o mwuWzVLoqppaMc+IxpDgEadCo8A5KN5kAowzXavGM00/qaAhnOU0wVchD0YcDoXhSuim nJKhZbQSIruSqcBQtRkiwyYQczErU4eOwIWb3q6krpca5nxz78ZcTG0ak+jRqWRCCw6M adOIQoZ6ZpnsKfOxT4hO1ELM8Vf/Jnlfz0hGJBvzwP+J0fyDw5lpA6UxVqvMWhCy0cRJ kO6WCcfrPSs0Bfx8Xns1kSo2CHQOfzXtIn76v5WUieA7dew5i51Jke0Tm+mPrhXpE7UC uIiA== X-Gm-Message-State: AOJu0YzymcrptSQLjZZGT62VQ/W3Orqwvqp2m1NJCkVwjHTLTtXxIp3m EklnHYpQ3YDKlLNEqirdz9BHP/h1hrJkWEyd7YyiiQQZhjE= X-Google-Smtp-Source: AGHT+IG3eL19WSuu49+Uucq/ug198dToa+wGuaHWn0vt21wFobuvF9ILzeLbYy1H3UYawEODwto6Xgod8kWd02m4nF8= X-Received: by 2002:a17:907:98a:b0:9ae:69b8:322b with SMTP id bf10-20020a170907098a00b009ae69b8322bmr1873187ejc.60.1698855094828; Wed, 01 Nov 2023 09:11:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Damien Mattei Date: Wed, 1 Nov 2023 17:11:12 +0100 Message-ID: Subject: Re: unbound location: * To: kawa mailing list , Per Bothner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: if i modify a bit this version with define-variable instead of define, it seems to go further as i got an infinite loop: #|kawa:1|# (load "/Users/mattei/Dropbox/git/Scheme-PLUS-for-Kawa/main-test-define.scm") Exception in thread "main" java.lang.StackOverflowError at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172) at gnu.mapping.Environment.getCurrent(Environment.java:373) at gnu.mapping.DynamicLocation.lookup(DynamicLocation.java:28) at gnu.mapping.DynamicLocation.isBound(DynamicLocation.java:46) at gnu.kawa.reflect.FieldLocation.isBound(FieldLocation.java:360) at gnu.mapping.SharedLocation.isBound(SharedLocation.java:34) at gnu.mapping.InheritingEnvironment.getLocation(InheritingEnvironment.= java:71) at gnu.mapping.DynamicLocation.lookup(DynamicLocation.java:29) at gnu.mapping.DynamicLocation.isBound(DynamicLocation.java:46) at gnu.kawa.reflect.FieldLocation.isBound(FieldLocation.java:360) at gnu.mapping.SharedLocation.isBound(SharedLocation.java:34) at gnu.mapping.InheritingEnvironment.getLocation(InheritingEnvironment.= java:71) at gnu.mapping.DynamicLocation.lookup(DynamicLocation.java:29) at gnu.mapping.DynamicLocation.isBound(DynamicLocation.java:46) at gnu.kawa.reflect.FieldLocation.isBound(FieldLocation.java:360) at gnu.mapping.SharedLocation.isBound(SharedLocation.java:34) at gnu.mapping.InheritingEnvironment.getLocation(InheritingEnvironment.= java:71) at gn .... On Wed, Nov 1, 2023 at 3:02=E2=80=AFPM Damien Mattei wrote: > > i post a version of my problem independent to Scheme+. > in two attached files containing this kawa code code: > (module-name test-define) > > (require 'srfi-1) > > (export +) > > > (define (check-arguments pred-list args) > (if (=3D (length pred-list) (length args)) > (let ((pred-arg-list (map cons pred-list args))) > ;;(andmap (lambda (p) ((car p) (cdr p))) > ;; replace andmap with every in Guile > (every (lambda (p) ((car p) (cdr p))) > pred-arg-list)) > #f)) > > > (define (create-overloaded-existing-operator orig-funct funct > pred-list) ;; works for associative operators > > (display "create-overloaded-existing-operator") > (display " : pred-list =3D ") (display pred-list) (newline) > (define old-funct orig-funct) > (define new-funct (lambda args ;; args is the list of arguments > ;; (display "new-funct: new-funct =3D ") (display > new-funct) (newline) > ;; (display "new-funct : pred-list =3D ") (display > pred-list) (newline) > ;; (display "new-funct : args =3D ") (display args) (newlin= e) > (define nb-args (length args)) > ;;(display "new-funct : nb-args =3D ") (display nb-args) (n= ewline) > (cond ((check-arguments pred-list args) ;;(begin > ;;(display "new funct :calling:") > (display funct) (newline) > (apply funct args));;) > ((> nb-args 2) (new-funct (car args) > (apply new-funct (cdr args)))) ;; > op(a,b,...) =3D op(a,op(b,...)) > (else > ;;(begin > ;;(display "new funct :calling: ") (display > old-funct) (newline) > (apply old-funct args)))));;) > > (display "funct: ") (display funct) (newline) > (display "orig-funct: ") (display orig-funct) (newline) > (display "old-funct: ") (display old-funct) (newline) > (display "new-funct: ") (display new-funct) (newline) > > ;;(replace-operator! orig-funct new-funct) > > new-funct) > > (define-syntax overload-existing-operator > > (syntax-rules () > > ((_ orig-funct funct (pred-arg1 ...)) > (define orig-funct (create-overloaded-existing-operator > orig-funct funct (list pred-arg1 ...)))))) > > > > ; first stage overloading > ;;(define-overload-existing-operator +) ;; dummy in this implementation > > > > ; second stage overloading > (overload-existing-operator + vector-append (vector? vector?)) > > > (display +) (newline) > > > > and a simple main: > (require test-define) > > (define rv (+ #(1 2) #(3 4 5))) > (newline) (display "rv=3D") (display rv) (newline) > > i load it this way: > > kawa -Dkawa.import.path=3D".:/Users/mattei/Dropbox/git/Scheme-PLUS-for-Ka= wa:./kawa" > > (load "/Users/mattei/Dropbox/git/Scheme-PLUS-for-Kawa/main-test-define.sc= m") > > #|kawa:1|# (load > "/Users/mattei/Dropbox/git/Scheme-PLUS-for-Kawa/main-test-define.scm") > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/test-= define.scm:63:29: > unbound location: + > at gnu.mapping.PlainLocation.get(PlainLocation.java:22) > at test-define.run(test-define.scm:63) > at gnu.expr.ModuleBody.run(ModuleBody.java:51) > at gnu.expr.ModuleBody.run(ModuleBody.java:35) > at atInteractiveLevel-2.run(main-test-define.scm:1) > at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290) > at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211) > at kawa.Shell.run(Shell.java:289) > at kawa.Shell.runFile(Shell.java:551) > at kawa.standard.load.apply2(load.java:67) > at kawa.standard.load.apply1(load.java:27) > at gnu.mapping.Procedure1or2.applyToObject(Procedure1or2.java:64) > at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:75) > at gnu.mapping.CallContext.runUntilDone(CallContext.java:586) > at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:343) > at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211) > at kawa.Shell.run(Shell.java:289) > at kawa.Shell.run(Shell.java:196) > at kawa.Shell.run(Shell.java:183) > at kawa.repl.processArgs(repl.java:724) > at kawa.repl.main(repl.java:830) > > On Wed, Nov 1, 2023 at 1:50=E2=80=AFPM Damien Mattei wrote: > > > > a simpler example that lead to the same error: > > > > (module-name test-define) > > > > (require Scheme+) > > > > (export +) > > > > ; first stage overloading > > (define-overload-existing-operator +) > > > > > > > > ; second stage overloading > > (overload-existing-operator + vector-append (vector? vector?)) > > > > > > (display +) (newline) > > > > > > a main file: > > > > (require test-define) > > > > (define rv (+ #(1 2) #(3 4 5))) > > (newline) (display "rv=3D") (display rv) (newline) > > > > result: > > #|kawa:1|# (load > > "/Users/mattei/Dropbox/git/Scheme-PLUS-for-Kawa/main-test-define.scm") > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/arr= ay.scm:89:6: > > warning - void-valued expression where value is needed > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:15:10: > > warning - no use of only-one? > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:18:10: > > warning - no use of pair-list? > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:21:10: > > warning - no use of empty? > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:54:10: > > warning - no use of insertNoDups > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:61:10: > > warning - no use of remove-duplicates > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:67:10: > > warning - no use of singleton-list? > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:73:10: > > warning - no use of create-list > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:88:10: > > warning - no use of uniq > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:97:10: > > warning - no use of remove-firsts-elements > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:115:10: > > warning - no use of remove-last > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:157:10: > > warning - no use of debut > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:162:10: > > warning - no use of debut-iter > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:173:10: > > warning - no use of not-list? > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:181:10: > > warning - no use of before-element > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:189:10: > > warning - no use of start-with-element > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/lis= t.scm:198:10: > > warning - no use of pair-list-elements > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/ove= rload.scm:399:10: > > warning - no use of > > find-getter-and-setter-for-overloaded-square-brackets > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/app= ly-square-brackets.scm:332:7: > > warning - void-valued expression where value is needed > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/app= ly-square-brackets.scm:337:7: > > warning - void-valued expression where value is needed > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/arr= ay.scm: > > note - skipped 0 errors, 29 warnings, 0 notes > > /Users/mattei/Library/CloudStorage/Dropbox/git/Scheme-PLUS-for-Kawa/tes= t-define.scm:13:29: > > unbound location: + > > at gnu.mapping.PlainLocation.get(PlainLocation.java:22) > > at test-define.run(test-define.scm:13) > > at gnu.expr.ModuleBody.run(ModuleBody.java:51) > > at gnu.expr.ModuleBody.run(ModuleBody.java:35) > > at atInteractiveLevel-2.run(main-test-define.scm:1) > > at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290) > > at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211) > > at kawa.Shell.run(Shell.java:289) > > at kawa.Shell.runFile(Shell.java:551) > > at kawa.standard.load.apply2(load.java:67) > > at kawa.standard.load.apply1(load.java:27) > > at gnu.mapping.Procedure1or2.applyToObject(Procedure1or2.java:64) > > at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:75) > > at gnu.mapping.CallContext.runUntilDone(CallContext.java:586) > > at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:343) > > at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211) > > at kawa.Shell.run(Shell.java:289) > > at kawa.Shell.run(Shell.java:196) > > at kawa.Shell.run(Shell.java:183) > > at kawa.repl.processArgs(repl.java:724) > > at kawa.repl.main(repl.java:830) > > > > why + is unbound? in the worse case i should still have the default add= ition,no? > > > > seems something is crashing in this code without any element to debug: > > (define (create-overloaded-existing-operator orig-funct funct > > pred-list) ;; works for associative operators > > > > (display "create-overloaded-existing-operator") > > (display " : pred-list =3D ") (display pred-list) (newline) > > (define old-funct orig-funct) > > (define new-funct (lambda args ;; args is the list of arguments > > ;; (display "new-funct: new-funct =3D ") (display > > new-funct) (newline) > > ;; (display "new-funct : pred-list =3D ") (display > > pred-list) (newline) > > ;; (display "new-funct : args =3D ") (display args) (newl= ine) > > (define nb-args (length args)) > > ;;(display "new-funct : nb-args =3D ") (display nb-args) = (newline) > > (cond ((check-arguments pred-list args) ;;(begin > > ;;(display "new funct :calling:") > > (display funct) (newline) > > (apply funct args));;) > > ((> nb-args 2) (new-funct (car args) > > (apply new-funct (cdr args)))) ;; > > op(a,b,...) =3D op(a,op(b,...)) > > (else > > ;;(begin > > ;;(display "new funct :calling: ") (display > > old-funct) (newline) > > (apply old-funct args)))));;) > > > > (display "funct: ") (display funct) (newline) > > (display "orig-funct: ") (display orig-funct) (newline) > > (display "old-funct: ") (display old-funct) (newline) > > (display "new-funct: ") (display new-funct) (newline) > > > > (replace-operator! orig-funct new-funct) > > > > new-funct) > > > > On Wed, Nov 1, 2023 at 1:22=E2=80=AFPM Damien Mattei wrote: > > > > > > here is a counter example: > > > > > > ;; test-define.scm > > > > > > (module-name test-define) > > > > > > (export *) > > > > > > (display *) (newline) > > > > > > (define * +) > > > > > > (display *) (newline) > > > > > > ;; main-test-define.scm > > > > > > (require test-define) > > > > > > (define rv (* 2 3)) > > > (display rv) (newline) > > > > > > #|kawa:1|# (load > > > "/Users/mattei/Dropbox/git/Scheme-PLUS-for-Kawa/main-test-define.scm"= ) > > > # > > > # > > > 5 > > > > > > but i do not quite understand , first display shoud have display # > > > but no it displays # > > > > > > > > > On Wed, Nov 1, 2023 at 9:39=E2=80=AFAM Damien Mattei wrote: > > > > > > > > hello, > > > > > > > > i created a module this way: > > > > > > > > (module-name "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 > > > > *) > > > > > > > > (require Scheme+) > > > > > > > > > > > > ;; (matrix #(1 2 3)) > > > > ;; matrix@4612b856 > > > > > > > > > > > > (define-simple-class matrix () > > > > > > > > (v :: vector) > > > > > > > > ((*init* (vParam :: vector)) > > > > (set! v vParam)) > > > > > > > > ) > > > > > > > > (display "multiply : * =3D") (display *) (newline) > > > > > > > > > > > > ;; (define M (create-matrix-by-function (lambda (i j) (+ i j)) 2 3)= ) > > > > (define (create-matrix-by-function fct lin col) > > > > (matrix (create-vector-2d fct lin col))) > > > > > > > > > > > > ;; return the line and column values of dimension > > > > ;; (dim-matrix M) > > > > ;; 2 3 > > > > (define (dim-matrix M) > > > > > > > > (when (not (matrix? M)) > > > > (error "argument is not of type matrix")) > > > > > > > > {v <+ (matrix-v M)} > > > > {lin <+ (vector-length v)} > > > > {col <+ (vector-length {v[0]})} > > > > (values lin col)) > > > > > > > > ;; #|kawa:85|# (define M1 (create-matrix-by-function (lambda (i j) = (+ > > > > i j)) 2 3)) > > > > ;; #|kawa:86|# (define M2 (create-matrix-by-function (lambda (i j) = (+ > > > > i j)) 3 2)) > > > > ;; #|kawa:87|# (multiply-matrix-matrix M1 M2) > > > > ;; matrix@3fc1abf > > > > ;; #|kawa:88|# (define M1*M2 (multiply-matrix-matrix M1 M2)) > > > > ;; #|kawa:89|# M1*M2 > > > > ;; matrix@3bf5911d > > > > ;; #|kawa:90|# (matrix-v M1*M2) > > > > ;; #(#(5 8) #(8 14)) > > > > ;; #|kawa:91|# (matrix-v M1) > > > > ;; #(#(0 1 2) #(1 2 3)) > > > > ;; #|kawa:92|# (matrix-v M2) > > > > ;; #(#(0 1) #(1 2) #(2 3)) > > > > (define (multiply-matrix-matrix M1 M2) > > > > > > > > {(n1 p1) <+ (dim-matrix M1)} > > > > {(n2 p2) <+ (dim-matrix M2)} > > > > > > > > (when {p1 =E2=89=A0 n2} (error "matrix.* : matrix product impossi= ble, > > > > incompatible dimensions")) > > > > > > > > {v1 <+ (matrix-v M1)} > > > > {v2 <+ (matrix-v M2)} > > > > > > > > (define (res i j) > > > > {sum <+ 0} > > > > (for ({k <+ 0} {k < p1} {k <- k + 1}) > > > > {sum <- sum + v1[i][k] * v2[k][j]}) > > > > (display "sum=3D")(display sum) (newline) > > > > sum) > > > > > > > > {v <+ (create-vector-2d res n1 p2)} > > > > > > > > (matrix v)) > > > > > > > > > > > > > > > > (overload-existing-operator * multiply-matrix-matrix (matrix? matri= x?)) > > > > > > > > > > > > > > > > .... > > > > > > > > i cut off the whole code, the code used to works with 'include' , n= ow > > > > that i try with modules i stuck on this error at the line > > > > (overload-existing-operator * multiply-matrix-matrix (matrix? matri= x?)) > > > > > > > > note that matrix+.scm is converted externally in matrix.scm : > > > > > > > > (module-name "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 *) > > > > (require Scheme+) > > > > (define-simple-class matrix () (v :: vector) > > > > ((*init* (vParam :: vector)) (set! v vParam))) > > > > (display "multiply : * =3D") > > > > (display *) > > > > (newline) > > > > (define (create-matrix-by-function fct lin col) > > > > (matrix (create-vector-2d fct lin col))) > > > > (define (dim-matrix M) > > > > (when (not (matrix? M)) (error "argument is not of type matrix")) > > > > (<+ v (matrix-v M)) (<+ lin (vector-length v)) > > > > (<+ col (vector-length (bracket-apply v 0))) (values lin col)) > > > > (define (multiply-matrix-matrix M1 M2) (<+ (n1 p1) (dim-matrix M1)) > > > > (<+ (n2 p2) (dim-matrix M2)) > > > > (when (|=E2=89=A0| p1 n2) > > > > (error "matrix.* : matrix product impossible, incompatible dimens= ions")) > > > > (<+ v1 (matrix-v M1)) (<+ v2 (matrix-v M2)) > > > > (define (res i j) (<+ sum 0) > > > > (for ((<+ k 0) (< k p1) ($nfx$ k <- k + 1)) > > > > ($nfx$ sum <- sum + (bracket-apply (bracket-apply v1 i) k) * > > > > (bracket-apply (bracket-apply v2 k) j))) > > > > (display "sum=3D") (display sum) (newline) sum) > > > > (<+ v (create-vector-2d res n1 p2)) (matrix v)) > > > > (overload-existing-operator * multiply-matrix-matrix (matrix? matri= x?)) > > > > (define (matrix-v M) (slot-ref M (quote v))) > > > > (define (vector->matrix-column v) > > > > (matrix (vector-map (lambda (x) (make-vector 1 x)) v))) > > > > (define (matrix-column->vector Mc) (<+ v (matrix-v Mc)) > > > > (vector-map (lambda (v2) (bracket-apply v2 0)) v)) > > > > (define (multiply-matrix-vector M v) (<+ Mc (vector->matrix-column = v)) > > > > (matrix-column->vector (multiply-matrix-matrix M Mc))) > > > > (define (matrix-ref M lin col) (<+ v (matrix-v M)) > > > > (bracket-apply (bracket-apply v lin) col)) > > > > (define (matrix-set! M lin col x) (<+ v (matrix-v M)) > > > > (<- (bracket-apply (bracket-apply v lin) col) x)) > > > > (define (matrix-line-ref M lin) (<+ v (matrix-v M)) (bracket-apply = v lin)) > > > > (define (matrix-line-set! M lin vect-line) (<+ v (matrix-v M)) > > > > (<- (bracket-apply v lin) vect-line)) > > > > (overload-square-brackets matrix-ref matrix-set! (matrix? number? n= umber?)) > > > > (overload-square-brackets matrix-line-ref matrix-line-set! (matrix?= number?)) > > > > > > > > > > > > overload-existing-operator redefine the * operator , so basically i= t > > > > needs the original one to not loose the * between numbers > > > > the code is: > > > > > > > > (define-syntax overload-existing-operator > > > > > > > > (syntax-rules () > > > > > > > > ((_ orig-funct funct (pred-arg1 ...)) > > > > (define orig-funct (create-overloaded-existing-operator > > > > orig-funct funct (list pred-arg1 ...)))))) > > > > > > > > (define (create-overloaded-existing-operator orig-funct funct > > > > pred-list) ;; works for associative operators > > > > > > > > (display "create-overloaded-existing-operator") > > > > (display " : pred-list =3D ") (display pred-list) (newline) > > > > (define old-funct orig-funct) > > > > (define new-funct (lambda args ;; args is the list of arguments > > > > ;; (display "new-funct: new-funct =3D ") (display > > > > new-funct) (newline) > > > > ;; (display "new-funct : pred-list =3D ") (display > > > > pred-list) (newline) > > > > ;; (display "new-funct : args =3D ") (display args) (= newline) > > > > (define nb-args (length args)) > > > > ;;(display "new-funct : nb-args =3D ") (display nb-ar= gs) (newline) > > > > (cond ((check-arguments pred-list args) ;;(begin > > > > ;;(display "new funct :calling:") > > > > (display funct) (newline) > > > > (apply funct args));;) > > > > ((> nb-args 2) (new-funct (car args) > > > > (apply new-funct (cdr args)))) ;; > > > > op(a,b,...) =3D op(a,op(b,...)) > > > > (else > > > > ;;(begin > > > > ;;(display "new funct :calling: ") (display > > > > old-funct) (newline) > > > > (apply old-funct args)))));;) > > > > > > > > (display "funct: ") (display funct) (newline) > > > > (display "orig-funct: ") (display orig-funct) (newline) > > > > (display "old-funct: ") (display old-funct) (newline) > > > > (display "new-funct: ") (display new-funct) (newline) > > > > > > > > (replace-operator! orig-funct new-funct) > > > > > > > > new-funct) > > > > > > > > this weird code return the new-funct which is the overloaded * , a= t > > > > the line (overload-existing-operator * multiply-matrix-matrix > > > > (matrix? matrix?)) > > > > > > > > i got this error: > > > > Exception in thread "main" java.lang.ExceptionInInitializerError > > > > at atInteractiveLevel-8.run(exo_retropropagationNhidden_layers_= matrix_v2_by_vectors4kawa+.scm:43) > > > > at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290) > > > > at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211) > > > > at kawa.Shell.run(Shell.java:289) > > > > at kawa.Shell.runFile(Shell.java:551) > > > > at kawa.standard.load.apply2(load.java:67) > > > > at kawa.standard.load.apply1(load.java:27) > > > > at gnu.mapping.Procedure1or2.applyToObject(Procedure1or2.java:6= 4) > > > > at gnu.mapping.Procedure.applyToConsumerDefault(Procedure.java:= 75) > > > > at gnu.mapping.CallContext.runUntilDone(CallContext.java:586) > > > > at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:343) > > > > at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211) > > > > at kawa.Shell.run(Shell.java:289) > > > > at kawa.Shell.run(Shell.java:196) > > > > at kawa.Shell.run(Shell.java:183) > > > > at kawa.repl.processArgs(repl.java:724) > > > > at kawa.repl.main(repl.java:830) > > > > Caused by: /Users/mattei/Library/CloudStorage/Dropbox/git/AI_Deep_L= earning/kawa/matrix.scm:9:10: > > > > unbound location: * > > > > at gnu.mapping.PlainLocation.get(PlainLocation.java:22) > > > > at matrix.(matrix.scm:9) > > > > ... 17 more > > > > > > > > ok * seems not bound to any procedure > > > > > > > > when i display it for debug i got: > > > > > > > > multiply : * =3D% > > > > > > > > note that % is in reversed colors (white on black background) i can= not > > > > copy/paste it.... > > > > > > > > all the code is called from a main file: > > > > > > > > (require matrix) > > > > (require array) > > > > > > > > (require Scheme+) > > > > > > > > it seems in a module * is not bound to anything, i had a same probl= em > > > > in Racket where i need to import racket/base, is there such a need = in > > > > Kawa? ,i can find anything related in the doc. > > > > > > > > regards, > > > > damien