Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prelisp: support for keyword parameters #107

Open
GlowingScrewdriver opened this issue Nov 5, 2024 · 1 comment
Open

Prelisp: support for keyword parameters #107

GlowingScrewdriver opened this issue Nov 5, 2024 · 1 comment

Comments

@GlowingScrewdriver
Copy link
Contributor

Consider the following Python function:

# In macro module
def include (headers, functions = [], structs = []):
    pass # Body

By design, either functions or structs can be unspecified (i.e. None). At present, the only way to specify structs in a macro call while leaving functions empty is the following:

; In source program
,(include (header-name) () (struct-name1 struct-name2))

This could be made much more elegant with the use of keyword arguments. Consider the following procedure definition, mimicking the macro, in Guile Scheme:

(define* (include headers #:key functions structs)
    '()) ; Body

This scheme procedure can be called as follows:

(include (header-name) #:structs (struct-name1 struct-name2))

The most obvious benefit offered by keyword arguments in this case is that the empty list () needn't be passed as a parameter; the functions parameter can simply be omitted. It is also important to note that while many members of the Scheme family offer keyword parameters, it is not part of the Scheme spec.

Adopting a similar pattern, the original macro call can be made to look like this:

; In source program
,(include (header-name) #:structs (struct-name1 struct-name2))
@GlowingScrewdriver
Copy link
Contributor Author

A few more notes on the topic:

  1. I can think of an alternative syntax to the macro call, one which would be much simpler to implement and read:

    ; In source program
    ,(include (header-name) (#:structs (struct-name1 struct-name2)))

    The difference between this and the Guile implementation is that here, the keyword and value are specified as a pair and that pair is supplied as an argument, rather than they keyword and value being two separate arguments.

  2. A keyword can be detected by the keyword? Guile Scheme procedure, like this:

    (keyword? #:key-name) ; result: #t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant