5
54
Fork
You've already forked blue
4

Default value of state variable #71

Closed
opened 2025年08月22日 16:25:09 +02:00 by old · 10 comments
Owner
Copy link

Given for example a build command that do this:

(define-command (build-command arguments)
 ((invoke "build"))
 (parameterize ((current-c-toolchain #%?CC))
 (require ...)))

This command will parameterize the current C toolchain for compiling <c-binary> with the value of the variable CC. However, that variable could be not defined in the blueprint configuration at all. But it can also be defined dynamically by the user by doing ./configure CC=gcc. Thus, it is entirely possible for a variable to maybe defined.

Currently, trying to lookup a state variable that is not defined will raise an exception. And so the current way of handling this is to do:

(define-command (build-command arguments)
 ((invoke "build"))
 (parameterize ((current-c-toolchain (or (false-if-exception #%?CC) "gcc")))
 (require ...)))

I think it could be interesting to have a way to specify a default value instead of raising an exception. For example, we could do #%?CC|"gcc"|. So now, either the variable CC is defined and its value is returned, or the string "gcc" is returned.

Thus one could do:

(define-command (build-command arguments)
 ((invoke "build"))
 (parameterize ((current-c-toolchain #%?CC|"gcc"|))
 (require ...)))

Thoughts?

Given for example a build command that do this: ```scheme (define-command (build-command arguments) ((invoke "build")) (parameterize ((current-c-toolchain #%?CC)) (require ...))) ``` This command will parameterize the current C toolchain for compiling `<c-binary>` with the value of the variable `CC`. However, that variable could be not defined in the blueprint configuration at all. But it can also be defined dynamically by the user by doing `./configure CC=gcc`. Thus, it is entirely possible for a variable to **maybe** defined. Currently, trying to lookup a state variable that is not defined will raise an exception. And so the current way of handling this is to do: ```scheme (define-command (build-command arguments) ((invoke "build")) (parameterize ((current-c-toolchain (or (false-if-exception #%?CC) "gcc"))) (require ...))) ``` I think it could be interesting to have a way to specify a default value instead of raising an exception. For example, we could do `#%?CC|"gcc"|`. So now, either the variable `CC` is defined and its value is returned, or the string `"gcc"` is returned. Thus one could do: ```scheme (define-command (build-command arguments) ((invoke "build")) (parameterize ((current-c-toolchain #%?CC|"gcc"|)) (require ...))) ``` Thoughts?

I like the idea. The syntax does not look very lispy but I cannot think of anything better...

I like the idea. The syntax does not look very lispy but I cannot think of anything better...
Author
Owner
Copy link

Well it could be this:

#%?CC("gcc")

So really the template is:

#%?VARIABLE(expression)

So one could do this:

#%?CC((or (getenv "CC") "gcc"))

Or this:

;; #%?VARIABLE|expression|
#%?CC|(or (getenv "CC") "gcc")|
Well it could be this: ```scheme #%?CC("gcc") ``` So really the template is: ```scheme #%?VARIABLE(expression) ``` So one could do this: ```scheme #%?CC((or (getenv "CC") "gcc")) ``` Or this: ```scheme ;; #%?VARIABLE|expression| #%?CC|(or (getenv "CC") "gcc")| ```

I think I find this one less confusing:

;; #%?VARIABLE|expression|
#%?CC|(or (getenv "CC") "gcc")|

The other one looks like you are evaluating a function.

I think I find this one less confusing: ``` ;; #%?VARIABLE|expression| #%?CC|(or (getenv "CC") "gcc")| ``` The other one looks like you are evaluating a function.
Author
Owner
Copy link

Note that this prevent the usage of | in variable name then.

Note that this prevent the usage of `|` in variable name then.

Oh, well. That's a good reason not to do that, I guess. We can go with the (...) syntax.

Oh, well. That's a good reason not to do that, I guess. We can go with the `(...)` syntax.
Author
Owner
Copy link

I'm moving this to backlog since I don't quite like the syntax and will wait until the issue arise more.

I'm moving this to backlog since I don't quite like the syntax and will wait until the issue arise more.
old added this to the Backlog project 2025年09月10日 00:30:28 +02:00
Author
Owner
Copy link

Remove. Just use computation-ask/cps

Remove. Just use `computation-ask/cps`

@old wrote in #71 (comment):

Remove. Just use computation-ask/cps

That's fine, although as a user that name is not telling me much. Please, could you give the rationale for the /cps suffix?

@old wrote in https://codeberg.org/lapislazuli/blue/issues/71#issuecomment-8886648: > Remove. Just use `computation-ask/cps` That's fine, although as a user that name is not telling me much. Please, could you give the rationale for the `/cps` suffix?
Author
Owner
Copy link

Continuation passing style. You pass the success and failure continuations as parameter so you don't have to check the returned value.

(computation-ask/cps 'FOO (lambda (value) (pk 'success value)) (lambda () (pk 'error)))
Continuation passing style. You pass the success and failure continuations as parameter so you don't have to check the returned value. ```scheme (computation-ask/cps 'FOO (lambda (value) (pk 'success value)) (lambda () (pk 'error))) ```

Got it, we will have to be clear about this usage in the manual.

Got it, we will have to be clear about this usage in the manual.
Sign in to join this conversation.
No Branch/Tag specified
main
pipeline-operators
documentation
shadow-fields
instance-walker
blue-shell
promote-serializers-to-metacommands
pre-alpha
Labels
Clear labels
bug
Something is not working
contribution welcome
Contributions are very welcome, get started here
discussion
duplicate
This issue or pull request already exists
enhancement
New feature
good first issue
Interested in contributing? Get started here.
help wanted
Need some help
invalid
Something is wrong
optimization
question
More information is needed
upstream
Related to an upstream repository, already reported there
bug
Something is not working
contribution welcome
Contributions are very welcome, get started here
duplicate
This issue or pull request already exists
enhancement
New feature
good first issue
Interested in contributing? Get started here.
help wanted
Need some help
invalid
Something is wrong
question
More information is needed
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lapislazuli/blue#71
Reference in a new issue
lapislazuli/blue
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?