Skip to content

Add lambdas for Go#85

Merged
jgonggrijp merged 1 commit into
mustache:masterfrom
jabley:feature/go-lambdas
Oct 30, 2023
Merged

Add lambdas for Go#85
jgonggrijp merged 1 commit into
mustache:masterfrom
jabley:feature/go-lambdas

Conversation

@jabley

@jabley jabley commented Jan 4, 2015

Copy link
Copy Markdown
Contributor

No description provided.

jabley added a commit to jabley/mustache that referenced this pull request Jan 4, 2015
See mustache/spec#85 for how the tests were
generated. If / when that pull request is merged, I will also update the
submodule reference in this project.

“Lambdas are a special-cased data type for use in interpolations and
sections.

“When used as the data value for an Interpolation tag, the lambda MUST
be treatable as an arity 0 function, and invoked as such.  The returned
value MUST be rendered against the default delimiters, then interpolated
in place of the lambda.

When used as the data value for a Section tag, the lambda MUST be
treatable as an arity 1 function, and invoked as such (passing a String containing the unprocessed section contents).  The returned value MUST
be rendered against the current delimiters, then interpolated in place
of the section.”
@jabley

jabley commented May 18, 2016

Copy link
Copy Markdown
Contributor Author

How can I help this progress?

@jgonggrijp

Copy link
Copy Markdown
Member

@jabley I'm going to help you get this merged. Would you like to update your branch first?

Comment thread specs/~lambdas.yml Outdated
clojure: '(def g (atom 0)) (fn [] (swap! g inc))'
lisp: '(let ((g 0)) (lambda () (incf g)))'
pwsh: 'if (($null -eq $script:calls) -or ($script:calls -ge 3)){$script:calls=0}; ++$script:calls; $script:calls'
go: 'func() func()(string) { g := 0; return func() string { g++; return strconv.Itoa(g); } } ()'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why convert the integer to string? If possible, I would prefer that you declare that the function returns an integer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring a string was a limitation of the mustache implementation that I originally wrote, but there's no reason to enforce that limitation, and I changed my version to happily handle other types.

@jgonggrijp jgonggrijp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jgonggrijp jgonggrijp merged commit 59be9b2 into mustache:master Oct 30, 2023
@jabley jabley mentioned this pull request Oct 31, 2023
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

Successfully merging this pull request may close these issues.

2 participants