Nested constants

new topic     » topic index » view thread      » older message » newer message

Managed to shoehorn a little featurette in yesterday, took less than an hour.

Instead of

 
                constant WSAEINTR   = 10004, 
                         WSAEACCES  = 10013 
                constant {ERROR_NO, ERROR_NAME, ERROR_SHORT} = columnize( 
                    {{WSAEINTR,         "WSAEINTR",  "Interrupted function call."}, 
                     {WSAEACCES,        "WSAEACCES", "Permission denied."}} 
 

(which gets more and more error prone and tedious as the tables grow in size) you can now define them all together like this:

 
                constant {ERROR_NO, ERROR_NAME, ERROR_SHORT} = columnize( 
                    {{WSAEINTR :=10004, "WSAEINTR",  "Interrupted function call."}, 
                     {WSAEACCES:=10013, "WSAEACCES", "Permission denied."}}) 
 

ie on the second line before the first ',' we see both a definition of WSAEINTR and a reference to it.

Specifically, a ":=" operator at the top level of a {} construct on the rhs of a constant definition is treated as a nested constant definition, and obviously you cannot clash with an existing name or overwrite an existing value.

Right pleased with that, I was.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu