Coder Social home page Coder Social logo

String interpolation about squint HOT 12 CLOSED

borkdude avatar borkdude commented on June 19, 2024
String interpolation

from squint.

Comments (12)

lilactown avatar lilactown commented on June 19, 2024

Nitpicking: #i is a bit ambiguous, what about #str?

from squint.

borkdude avatar borkdude commented on June 19, 2024

Yes, #i isn't a good choice. Not sure about #str, maybe too general?. What about #<<? << was the string interpolation macro in clojure.contrib. Too cryptic?

#<< "hello ${name}"

from squint.

borkdude avatar borkdude commented on June 19, 2024

Or #$ "hello ${name}: too Perly...

from squint.

lilactown avatar lilactown commented on June 19, 2024

Outside of the reader tag we use, how ought we to handle custom tag functions? Something that would expand to

html`<div style="color: red;">hello ${user}!</div>`

from squint.

lilactown avatar lilactown commented on June 19, 2024

perhaps we could allow passing in a list, like #tmpl (html "<div style=\"color: red;\">hello ${user}!</div>")

from squint.

corasaurus-hex avatar corasaurus-hex commented on June 19, 2024

maybe #` ? Some way to indicate that these are backticks?

from squint.

corasaurus-hex avatar corasaurus-hex commented on June 19, 2024

oh dang that's not bad @lilactown, I like it

from squint.

corasaurus-hex avatar corasaurus-hex commented on June 19, 2024

how does that generalize to bare template strings, though?

from squint.

lilactown avatar lilactown commented on June 19, 2024

i'm a bit ignorant of how the reader works is but i think we could have it support both bare strings as well as lists with a tag function

#tmpl "Hello, ${user}!"

#tmpl (html "<div style=\"color: red;\">hello ${user}!</div>")

I'm using tmpl as a stand in for whatever we decide to use.

from squint.

lilactown avatar lilactown commented on June 19, 2024

Thinking out loud, I'm worried about how we'll handle complex cases than just interpolating a variable. For instance, how should we handle expressions?

#tmpl "Hello, ${(:name user)}!"

Perhaps we should lean into the tag accepting a collection, and instead of writing the ${} syntax directly we write lists

#tmpl ("Hello, " user-name "!")
#tmpl ("Hello, " (:name user) "!")
#tmpl (html "<div style=\"color: red;\">Hello, " user-name "!</div>")

from squint.

borkdude avatar borkdude commented on June 19, 2024

#tmpl ("Hello, " user-name "!")

Hmm, this isn't any better to me than just using str. The point of "${foo}" is that it's easier to write.

We could support #tmpl "Hello ${name}" and #tmpl [:html "<pre>${name}</pre>].

from squint.

lilactown avatar lilactown commented on June 19, 2024

@borkdude how should we handle arbitrary expressions inside of the template string, like I was talking about above?

from squint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.