unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* can't export conditional variable set with 'cond'
@ 2024-01-23 13:37 Mortimer Cladwell
  2024-01-23 14:22 ` Damien Mattei
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Mortimer Cladwell @ 2024-01-23 13:37 UTC (permalink / raw)
  To: guile-user

Hi,

Suppose I have the following module "testexport" with the auxiliary module
"env.scm", used to set global environment variables:

-------------testexport.scm begin----------------------------------
(define-module (testexport)
  #:use-module (ice-9 pretty-print)
  #:use-module (env)
  )

(define (main)
  (pretty-print (string-append  "varA in main: " varA))
  (pretty-print (string-append  "varB in main: " varB))
  (pretty-print (string-append  "varC in main: " varC))
  )

(main)
-------------testexport.scm end----------------------------------

-------------env.scm begin----------------------------------
(define-module (env)
  #:use-module (ice-9 pretty-print)
  #:export(varA varB varC))

(define varA "A")
(define varB "")
(define varC "")
(define testval "x")

(cond
 ((string= testval "x") (set! varB "B"))
 ((string= testval "y") (set! varB "error"))
 ((string= testval "z") (set! varB "null"))
 )
(pretty-print (string-append "varB post cond: " varB))

(if (string= testval "x")  (set! varC "C"))
(pretty-print (string-append "varC post if: " varC))
-------------env.scm end----------------------------------

When I run the above I get as output:

"varB post cond: B"
"varC post if: C"
"varA in main: A"
"varB in main: "
"varC in main: C"

Why can I reset the variables with both 'cond' and 'if' in env.scm, but
only the variable reset with 'if' is exported with the updated value?
Thanks
Mortimer


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: can't export conditional variable set with 'cond'
@ 2024-02-02  8:15 Mortimer Cladwell
  0 siblings, 0 replies; 10+ messages in thread
From: Mortimer Cladwell @ 2024-02-02  8:15 UTC (permalink / raw)
  To: guile-user

Thanks all.
Both parameters and boxes work for me with guile-3.0.9, which is what I run
on my local machine.

>> I get the impression that you were asking this more for curiosity about
how the language implementation works than to solve a problem

I am trying to solve a problem. I have old code running on a remote server
using guile-3.0.5. When I pull to local (guile-3.0.9) that code no longer
works using 3.0.9. I find the problem is that globals are not properly
exported. If I run my original test code on the server - works fine
(without boxes, parameters).  To clarify I am using:

-------------testexport.scm begin----------------------------------
(define-module (testexport)
  #:use-module (ice-9 pretty-print)
  #:use-module (env)
  )

(define (main)
  (pretty-print (string-append  "varA in main: " varA))
  (pretty-print (string-append  "varB in main: " varB))
  (pretty-print (string-append  "varC in main: " varC))
  )

(main)
-------------testexport.scm end----------------------------------

------------env.scm begin-----------------------------------
(define-module (env)
  #:use-module (ice-9 pretty-print)
  #:export(varA varB varC))

(define varA "A")
(define varB "")
(define varC "")
(define testval "x")

(cond
 ((string= testval "x") (set! varB "B"))
 ((string= testval "y") (set! varB "error"))
 ((string= testval "z") (set! varB "null"))
 )
(pretty-print (string-append "varB post cond: " varB))

(if (string= testval "x")  (set! varC "C"))
(pretty-print (string-append "varC post if: " varC))
-------------env.scm end----------------------------------


remote server running guile 2.2.7:

admin@ip-172-31-16-153:~/testexport$  guile -L . ./testexport.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/admin/testexport/./testexport.scm
;;; compiling ./env.scm
;;; compiled
/home/admin/.cache/guile/ccache/2.2-LE-8-3.A/home/admin/testexport/env.scm.go
"varB post cond: B"
"varC post if: C"
;;; compiled
/home/admin/.cache/guile/ccache/2.2-LE-8-3.A/home/admin/testexport/testexport.scm.go
"varA in main: A"
"varB in main: B"
"varC in main: C"
admin@ip-172-31-16-153:~/testexport$ guile -v
guile (GNU Guile) 2.2.7
Copyright (C) 2020 Free Software Foundation, Inc.

License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

-----------------------------------------------------------------
remote server running guile-3.0.5:

admin@ip-172-31-16-153:~/testexport$
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/bin/guile -L .
./testexport.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/admin/testexport/./testexport.scm
;;; compiling ./env.scm
;;; compiled
/home/admin/.cache/guile/ccache/3.0-LE-8-4.4/home/admin/testexport/env.scm.go
"varB post cond: B"
"varC post if: C"
;;; compiled
/home/admin/.cache/guile/ccache/3.0-LE-8-4.4/home/admin/testexport/testexport.scm.go
"varA in main: A"
"varB in main: B"
"varC in main: C"


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-02-02  8:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23 13:37 can't export conditional variable set with 'cond' Mortimer Cladwell
2024-01-23 14:22 ` Damien Mattei
2024-01-24 20:07 ` Skyler Ferris
2024-02-01 12:06   ` Daniel Meißner
2024-02-01 14:53     ` M
2024-02-02  0:13     ` Skyler Ferris
2024-02-02  0:00 ` Skyler Ferris
2024-02-02  0:16   ` M
2024-02-02  0:25     ` Skyler Ferris
  -- strict thread matches above, loose matches on Subject: below --
2024-02-02  8:15 Mortimer Cladwell

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).