Skip to content
refractalize edited this page Apr 26, 2012 · 1 revision

Regular expressions in PogoScript are currently implemented using back-ticks:

filename: replace `.*\.jpg$` '.png'

This is because forward-slashes can't be distinguished from divide operators, eg:

a / b / c

Is this a divided by b divided by c, or a function a c that takes a regular expression / b /? Hard to tell. JavaScript can tell the difference because function arguments are always in parens, and are always after the function name.

Alternatively we could prefix the forward-slashes, say with an r:

filename: replace r/.*\.jpg$/ '.png'

This appears to be a bit more conventional than back-ticks. But, we should be able to generalise the syntax, firstly by allowing different delimiters. Let's try {}:

filename: replace r{.*\.jpg$} '.png'

Or, +:

filename: replace r+.*\.jpg$+ '.png'

Not dissimilar to Ruby's %r{} syntax.

And we could take it even further still by suggesting that r is a function on the string argument '.*\.jpg$'. The way we know is that there are no spaces between the r and the string. So we could define other functions such as u, to parse a URL:

get u"http://example.com/"

Which is equivalent to:

get (u "http://example.com/")

Not sure if that's confusing at all.

Clone this wiki locally