unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Setting variables in declarative modules
@ 2024-11-01  2:29 Tommi Höynälänmaa
  2024-11-01 13:20 ` Thompson, David
  0 siblings, 1 reply; 3+ messages in thread
From: Tommi Höynälänmaa @ 2024-11-01  2:29 UTC (permalink / raw)
  To: guile-user

Suppose that I have the following code in a Guile module:
---
(define fw-proc #f)

(define (my-proc x)
    (display (fw-proc x)))

(define (fw-proc x)
    (cons x x))
---

Can I declare the module as declarative?

     - Tommi Höynälänmaa


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

* Re: Setting variables in declarative modules
  2024-11-01  2:29 Setting variables in declarative modules Tommi Höynälänmaa
@ 2024-11-01 13:20 ` Thompson, David
  2024-11-01 15:28   ` Mikael Djurfeldt
  0 siblings, 1 reply; 3+ messages in thread
From: Thompson, David @ 2024-11-01 13:20 UTC (permalink / raw)
  To: Tommi Höynälänmaa; +Cc: Guile User

Hi Tommi,

On Thu, Oct 31, 2024 at 10:30 PM Tommi Höynälänmaa
<tommi.hoynalanmaa@gmail.com> wrote:
>
> Suppose that I have the following code in a Guile module:
> ---
> (define fw-proc #f)
>
> (define (my-proc x)
>     (display (fw-proc x)))
>
> (define (fw-proc x)
>     (cons x x))
> ---
>
> Can I declare the module as declarative?

Yes, this is fine. If you put this in a module file and compile it,
Guile does not issue any warnings. `define` is not `set!`. (Modules
are declarative by default, btw.)

- Dave



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

* Re: Setting variables in declarative modules
  2024-11-01 13:20 ` Thompson, David
@ 2024-11-01 15:28   ` Mikael Djurfeldt
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Djurfeldt @ 2024-11-01 15:28 UTC (permalink / raw)
  To: Thompson, David
  Cc: Tommi Höynälänmaa, Guile User, Mikael Djurfeldt

One additional comment regarding this:

The first definition in your example, Tommi, isn't required. The order of
the definitions don't matter as long as a variable reference isn't required
to compute the value being defined. In your case, the variable references
aren't resolved until the procedures are executed. Meanwhile the bindings
my-proc and fw-proc get their values just fine without a need to resolve
the reference to fw-proc inside my-proc.

On Fri, Nov 1, 2024 at 2:21 PM Thompson, David <dthompson2@worcester.edu>
wrote:

> Hi Tommi,
>
> On Thu, Oct 31, 2024 at 10:30 PM Tommi Höynälänmaa
> <tommi.hoynalanmaa@gmail.com> wrote:
> >
> > Suppose that I have the following code in a Guile module:
> > ---
> > (define fw-proc #f)
> >
> > (define (my-proc x)
> >     (display (fw-proc x)))
> >
> > (define (fw-proc x)
> >     (cons x x))
> > ---
> >
> > Can I declare the module as declarative?
>
> Yes, this is fine. If you put this in a module file and compile it,
> Guile does not issue any warnings. `define` is not `set!`. (Modules
> are declarative by default, btw.)
>
> - Dave
>
>


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

end of thread, other threads:[~2024-11-01 15:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-01  2:29 Setting variables in declarative modules Tommi Höynälänmaa
2024-11-01 13:20 ` Thompson, David
2024-11-01 15:28   ` Mikael Djurfeldt

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