flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > question about calm documentation example

Author
Thread Post new topic Reply to topic
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 28 Mar 2023, 07:43
Hi
In CALM doc, i find below example :
Code:
        calminstruction constdefine? var
                local val
                arrange val,
                match var=  val, var
                publish var:, val
        end calminstruction

        constdefine plus? +
    



what is the purpose here of
"arrange val, "
?
... If I try removing it, it seems to produce same result ...
... What am I missing ?
Post 28 Mar 2023, 07:43
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 28 Mar 2023, 08:00
It sets up the default empty value, for when the MATCH fails, because in such case no value is assigned to "var" and "val", and therefore "val" keeps whatever value it had previously. You should see the difference with a sequence like:
Code:
constdefine plus? +
constdefine test?    
Post 28 Mar 2023, 08:00
View user's profile Send private message Visit poster's website Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 28 Mar 2023, 08:18
Ok tx
I had vaguely thought about this, but defining empty symbolic constant seemed kinda pointless, so I was unsure ...

... could it then be rewritten as
Code:
        calminstruction constdefine? var
                local val
                match var=  val?, var
                publish var:, val
        end calminstruction

        constdefine plus? +
    


as the doc says :
(...)

If a pattern in CALM instruction has a "?" character immediately following the name of a wildcard, it does not affect how the symbol is identified (whether the used symbol is case-insensitive depends on what is present in the local scope at the time the instruction is defined). Instead, modifying the name of a wildcard with "?" allows it to be matched with an empty text.

(...)
Post 28 Mar 2023, 08:18
View user's profile Send private message Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 28 Mar 2023, 08:26
... actually I just tested it and it does not seem to be working ... I don't understand why though ...
Post 28 Mar 2023, 08:26
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 28 Mar 2023, 09:20
That's because "= " is a hard requirement for whitespace, which cannot be fulfilled when at the end of line.
Post 28 Mar 2023, 09:20
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.