From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 913D63858D33 for ; Thu, 19 Oct 2023 06:36:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 913D63858D33 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 913D63858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697697402; cv=none; b=jfpfmELwSjyWTrAPjwUGMkr6fa/UBfM7Cermo13FBJIgGc9SsfftARaBgd28yCGzAGzJqISu/qsVFyc8rehl9o0urXD6U2pQWeOW2BHqOpuOsTGJz6bXqYeeZOGBCale1LTYtv70rKcMi9o0lzuHyLzSDs5OOtRXZLJ+cJGS7P0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697697402; c=relaxed/simple; bh=TidmlDxr0mG2HdOAPssi7nZwuRpivMIAQa/9Ki/YNMM=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=u+d1Fw9NhNHUxm7lvRuOXb8X40wSETYg2Dwy1mY1nlw2tM7uRwGYJB5JPljs7BsxFKf4VrCwvOTJiVUQUK3DJKGtF8LHE/QsHgPCWfLeT/ClbWEjOq9YaepLY+6LbBBzQje3jA0B0xDFkgvVsSv9Z2D3QsczCyNYH2e6sZ7Mtsw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-9be02fcf268so890076866b.3 for ; Wed, 18 Oct 2023 23:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697697399; x=1698302199; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cXC9n68bjTpLsL0rUO1m2VRESDYo+OoY04d5gpsuxo8=; b=IcWnFTtovh2OTXvArI1Ut7+wF7y5RH+psV2NneU7RrcZJRWD9dgyWtdSF1pGAIQdMG 4XJkpup1pLWZ7WqGuKAAY7R1euK/f2i6e+2AjPOBz782vX81o4enYwezcbmgCGfm5m/i jvLTZYS4iPPF4qclE5aYYzyxobZfftNHMqFppiNbEW7tC+XWMDm3hBJfxl2MkxcJsnoD XQnp8e4KXD14oYa05LGJPLtl8hyiSrtTW8iGOSpklUC/qjWeetQni3gJ3/BRGDCTykFl nxba5pJnMOwQZWSf2mryRAMLlMVlydPAW/ocQH97X6ChLZcUynv08xFofAcx3LZjPVhs 41Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697697399; x=1698302199; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cXC9n68bjTpLsL0rUO1m2VRESDYo+OoY04d5gpsuxo8=; b=IXCEjjW+kNdzSNlxOORtNH6T5SCLWiOgbaSuguqOA3hV8y3ZeZqe62RCbRIxR0tT+W Fti7yX6MBQRUIYBuIioyvbvi2kw6CFz2pZsJ2jV8ZxCfsNd6WdkDIWRhLDgnu8opu5Cr h3snYVSbcLA7S1HCnwx+Fp0LT+zC9e8dLMv1LtwulEbCraVU1WrLwbLdlAIqrWgkNHgr sCQzh1hW3WQTmcpkrBK/ohdsCilAfGhqX7wabyCQKHsMy+a1BN2RPuoXSj4Dvwrf5MVt KMT6ULKLgzYt15JLo2fyByRCO3qdKTNFsWnjgjy/0oFVvEBRq4tY04tJC0eT1l5EdKrc cGpg== X-Gm-Message-State: AOJu0YxPlLXX2xykHSxiWVSwd1pgubpF19GV9nXsJHikqX9v2kqKgNm8 2bhEq/faGWaTRwTaFDs7U/hgYPGVS4/vwm5asAmgm5g9SYY= X-Google-Smtp-Source: AGHT+IGzZfXkYm57V3a77dYRhlV272Y1DMYOtldUCEwjO99bt3WoD95MIC3FJXMPoSwZnnFkMYXS/DCYOvnZ1tXRTNg= X-Received: by 2002:a17:907:c16:b0:9ae:59c9:b831 with SMTP id ga22-20020a1709070c1600b009ae59c9b831mr1078919ejc.49.1697697398583; Wed, 18 Oct 2023 23:36:38 -0700 (PDT) MIME-Version: 1.0 From: Damien Mattei Date: Thu, 19 Oct 2023 08:36:27 +0200 Message-ID: Subject: module protection To: kawa mailing list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 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 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: i have wrote, what i suppose be a module in kawa, but when using it in a main program, it seems that the inner definitions of module can be modified by the main program. for example the module is using $nfx$ from scheme-infix.scm but later in the main i include again scheme-infix.scm which use other operators (overloaded) and the $nfx$ of my module and its variables seems no more used. here is my definition of module, but is it really "water-proof"? ;; matrix ;; Kawa version ;; use with Scheme+: (require matrix) (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 'srfi-1) ; any,every (require 'srfi-69) ;; hash table ;; try include , use include-relative if problems (include "../../Scheme-PLUS-for-Kawa/rec.scm") ; rec does not exist in Kawa (no SRFI 31) (include "../../Scheme-PLUS-for-Kawa/def.scm") (include "../../Scheme-PLUS-for-Kawa/set-values-plus.scm") (include "../../Scheme-PLUS-for-Kawa/for_next_step.scm") (include "../../Scheme-PLUS-for-Kawa/declare.scm") (include "../../Scheme-PLUS-for-Kawa/condx.scm") (include "../../Scheme-PLUS-for-Kawa/block.scm") (include "../../Scheme-PLUS-for-Kawa/not-equal.scm") (include "../../Scheme-PLUS-for-Kawa/exponential.scm") (include "../../Scheme-PLUS-for-Kawa/while-do-when-unless.scm") (include "../../Scheme-PLUS-for-Kawa/repeat-until.scm") (include "../../Scheme-PLUS-for-Kawa/modulo.scm") (include "../../Scheme-PLUS-for-Kawa/bitwise.scm") (include "../../Scheme-PLUS-for-Kawa/slice.scm") (include "../../Scheme-PLUS-for-Kawa/scheme-infix.scm") (include "../../Scheme-PLUS-for-Kawa/assignment.scm") (include "../../Scheme-PLUS-for-Kawa/apply-square-brackets.scm") (include "../../Scheme-PLUS-for-Kawa/array.scm") ;; (matrix #(1 2 3)) ;; matrix@4612b856 (define-simple-class matrix () (v :: vector) ((*init* (vParam :: vector)) (set! v vParam)) ) ;; (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 impossible, 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]} )) {v <+ (create-vector-2d res n1 p2)} (matrix v)) ;; (matrix-v M) ;;#(#(0 1 2) ;; #(1 2 3)) (define (matrix-v M) (slot-ref M '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) {v2[0]}) v)) (define (multiply-matrix-vector M v) ;; args: matrix ,vector ; return vect= or {Mc <+ (vector->matrix-column v)} (matrix-column->vector (multiply-matrix-matrix M Mc))) ;; define getter,setter ;; (matrix-ref M 1 1) ;; 5 (define (matrix-ref M lin col) {v <+ (matrix-v M)} {v[lin][col]}) ;; (matrix-set! M 0 1 -7) ;; -7 ;; #|kawa:63|# (matrix-v M) ;; #(#(0 -7 2) #(4 5 6)) (define (matrix-set! M lin col x) {v <+ (matrix-v M)} {v[lin][col] <- x}) ;; (matrix-line-ref M 1) ;; #(1 2 3) (define (matrix-line-ref M lin) {v <+ (matrix-v M)} {v[lin]}) ;; (matrix-v M) ;; #(#(0 1 2) #(1 2 3)) ;; #|kawa:51|# (matrix-line-set! M 1 #(4 5 6)) ;; #(4 5 6) ;; #|kawa:52|# (matrix-v M) ;; #(#(0 1 2) #(4 5 6)) (define (matrix-line-set! M lin vect-line) {v <+ (matrix-v M)} {v[lin] <- vect-line}) the main program reload a lot of common file (includes): ; kawa -Dkawa.import.path=3D".:/Users/mattei/Dropbox/git/Scheme-PLUS-for-Ka= wa:./kawa" ; use: (load "exo_retropropagationNhidden_layers_matrix_v2_by_vectors4kawa+= .scm") ;;(include "../Scheme-PLUS-for-Kawa/Scheme+.scm") (require 'srfi-1) ; any,every (require 'srfi-69) ;; hash table (require matrix) (require overload) ;; try include , use include-relative if problems (include "../Scheme-PLUS-for-Kawa/rec.scm") ; rec does not exist in Kawa (no SRFI 31) (include "../Scheme-PLUS-for-Kawa/def.scm") (include "../Scheme-PLUS-for-Kawa/set-values-plus.scm") (include "../Scheme-PLUS-for-Kawa/for_next_step.scm") (include "../Scheme-PLUS-for-Kawa/declare.scm") (include "../Scheme-PLUS-for-Kawa/condx.scm") (include "../Scheme-PLUS-for-Kawa/block.scm") (include "../Scheme-PLUS-for-Kawa/not-equal.scm") (include "../Scheme-PLUS-for-Kawa/exponential.scm") (include "../Scheme-PLUS-for-Kawa/while-do-when-unless.scm") (include "../Scheme-PLUS-for-Kawa/repeat-until.scm") (include "../Scheme-PLUS-for-Kawa/modulo.scm") (include "../Scheme-PLUS-for-Kawa/bitwise.scm") (include "../Scheme-PLUS-for-Kawa/slice.scm") ; first stage overloading ;(define-overload-existing-operator +) ;(define-overload-existing-operator *) ; second stage overloading (overload-existing-operator + vector-append (vector? vector?)) (overload-existing-operator * multiply-matrix-matrix (matrix? matrix?)) (overload-existing-operator * multiply-matrix-vector (matrix? vector?)) (include "../Scheme-PLUS-for-Kawa/scheme-infix.scm") (include "../Scheme-PLUS-for-Kawa/assignment.scm") (include "../Scheme-PLUS-for-Kawa/apply-square-brackets.scm") (include "../Scheme-PLUS-for-Kawa/array.scm") (define M1 (create-matrix-by-function (lambda (i j) (+ i j)) 2 3)) (define M2 (create-matrix-by-function (lambda (i j) (+ i j)) 3 2)) (define M1*M2 (* M1 M2)) ;(define M1*M2 (multiply-matrix-matrix M1 M2)) (define vr (matrix-v M1*M2)) (display vr)