Having a hard time with maps
#123
Closed
opened 2 years ago by jaybonthius
·
4 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
I have a list of hashes called
hash_list
.I want to iterate through
hash_list
and generate a<video src="path/to/my/file.mp4" >
for each "video" key.Here's my attempt:
I'm getting a
decode-elements: contract violation
error, where it expectstxexpr-elements?
, and in thegiven
, I seeI might be wrong, but I think
decode-elements
would be happy if it was given this:Regardless, I'm not sure how to fix this. Would anyone mind pointing me in the right direction? Thanks!
Hi!
Note that the code that you wrote has missing parens, and is not a list of hashes. The list of hashes probably should be:
There are two possible mistakes here.
Notice that in the output, you have
(video [[src ("path/to/example_0000.mp4")]])
. This doesn't make sense, because the attributesrc
should be associated with a string value, not a list of strings.The fix could be done by changing
video-env
to consume exactly one argument instead of making it consume variadic arguments. That is, you would need to make a definition like this instead:(Notice the absence of dot. Also, people usually use
-
instead of_
in names)Notice that in the output, you have
((video ...) (video ...))
. This again doesn't make sense, because the body of the document should not be a list of elements. There are several ways to fix this. One possibility is:So, your final code might look like this:
which produces
test.html
afterraco pollen render test.html.pm
@sorawee That did the trick! Thank you so much for pointing out both errors and putting me on the right path. I'm beaming 😄
I dropped some parens in the hash lists when I wrote the question. Whoops!
FWIW:
default-tag-function
.@
explicitly and instead usefor/splice
(which gathers the results of the iteration under a@
automatically)So if you wished, you could simplify this example like so:
@mbutterick My hash table comes from parsing a
.json
with multiple values per record, which isn't obvious from my oversimplified example. Sorry about that. But your points ondefault-tag-function
andfor/splice
are taken! And thanks for giving an example, I appreciate it.