Skip to content

How to create a list with interpolated variables? #102

Answered by gilch
mjreed-wbd asked this question in Q&A
Discussion options

You must be logged in to vote

Nearest equivalent (this needs the bundled macros):

(define foo 'bar)
(en#tuple 1 foo 2)

Hissp code is based on tuples, not linked lists. Python's builtin tuple takes a single iterable argument. The en# reader macro uses a lambda to convert a function applicable to one tuple to a function of its elements.


Without any bundled macros (Scheme calls this "quasiquoting"):

(.update (globals) : foo 'bar)
`(,1 ,foo ,2)

This uses Python builtins to accomplish the assignment and the template quote reader syntax to make a data tuple. Notice how this also expands to a lambda. (Try it in the REPL.) The ints technically don't have to be unquoted here:

`(1 ,foo 2)

But make sure you understand how fragm…

Replies: 2 comments

This comment has been hidden.

Comment options

You must be logged in to vote
0 replies
Answer selected by gilch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #101 on July 28, 2021 06:12.