bugmake - Bugs: bug #43432, Two flavors of variable: describe...

 
 

bug #43432: Two flavors of variable: describe more aptly, in line with other languages.

Submitted by:  Kaz Kylheku <kkylheku>
Submitted on:  Fri 17 Oct 2014 06:50:57 PM UTC  
 
Severity: 3 - NormalItem Group: Documentation
Status: NonePrivacy: Public
Assigned to: NoneOpen/Closed: Open
Component Version: NoneOperating System: None
Fixed Release: NoneTriage Status: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 17 Oct 2014 06:50:57 PM UTC, original submission:

The GNU Make manual describes "two flavors of variable", at length. The "flavors" are called "recursively expanded" and "simply expanded".

In fact, the situation is that the := and ::= variables are more or less what people understand as variables in programming languages like the POSIX shell, Lisp or C. When the name of such a variable appears somewhere (perhaps with some special sygil syntax like $FOO, $(FOO) or ${FOO} or whatever), it behaves as an expression which is reduced to the value of the variable: what it contains.

The traditional make variables pretty much correspond to unparametrized macros: they are like preprocessor macros in the C language, or define-symbol-macro macros in Common Lisp. When an expression is evaluated which names a macro, that macro is understood to contain syntax which is substituted into that expression. That syntax is then evaluated in its place, which means that it is scanned for occurrences of more macros. This seems to be more or less exactly what happens with the classic make variables defined with the simple equal sign.

So the two flavors are simply "variable" versus "macro", and the = operator is not a variable assignment but in fact a macro definition like #define. The right hand side is not evaluated, but its syntax is stored into the left hand side symbol verbatim. When the symbol is later referenced, then that material is expanded: looks like a macro, walks like a macro, quacks like a macro, ...

When its left operand is a macro, the += operator behaves as a "macro append" (appending to a macro is found in some languages, like for instance in the troff typesetting language).

When its left operand is a variable, the += operator behaves as an append to a string.

Speaking of troff, it has parallel features: in troff you can define a string (.ds) and append to a string (.as). You can also define a macro (.de) and append to a macro (.am). Macros resemble strings, except that invoking a macro recursively expands (and can have arguments), whereas a string is just substituted verbatim and that is that. It is very similar to the two "flavors of variable" in GNU Make.

Troff also has something similar to $(call): a way of interpolating arguments into a variable, namely the \*[name arg1 arg2 ...] syntax where name is a string. This doesn't mean that "name" is a macro, just that this way of referencing it treats it as one.

Kaz Kylheku <kkylheku>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by kkylheku (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup1