?

Log in

No account? Create an account

Multi-culturalism - John C. Kirk

Oct. 11th, 2006

12:55 am - Multi-culturalism

Previous Entry Share Next Entry

Comments:

[User Picture]
From:pozorvlak
Date:October 11th, 2006 12:08 pm (UTC)
(Link)
To quote subsys: "You can't say pre (pre pub curry) pub without brackets. I think we should deprecate the English language".
(Reply) (Thread)
[User Picture]
From:totherme
Date:October 11th, 2006 12:44 pm (UTC)
(Link)
I think you can say "pub pre pre pub curry" though.... And you can do more if you allow commas and dashes :)
(Reply) (Parent) (Thread)
[User Picture]
From:pozorvlak
Date:October 11th, 2006 02:44 pm (UTC)
(Link)
Yay for infix notation! You could also use reverse polish notation, with the following BNF:
Social   ::= Ordering | "pub" | "curry"
Ordering ::= "pre" Social Social

[Note how I've surrounded that in <pre> tags...]
But how about (say) pre pre pre curry pub pub pre curry pre curry pub pub? Is that ambiguous, or just confusing (and downright unhealthy)? And it only works as long as "pub curry" doesn't have a separate meaning of a curry bought in a pub, and "pre" only takes a specified number of arguments (which is the /real/ reason Lisp needs all those brackets).
(Reply) (Parent) (Thread)
[User Picture]
From:johnckirk
Date:October 11th, 2006 03:12 pm (UTC)
(Link)
I think that "pub pre pre pub curry" is about as long as it can reasonably get, and even then you'd really need tone of voice/pauses to convey it properly. Beyond that, you get into the "buffalo buffalo buffalo ..." sentences which are technically valid but too confusing for real usage.

Coming back to my original example, one way to avoid brackets is to have something like BODMAS rules of precedence, e.g. to say that equal terms (such as "and") associate from right-to-left.
(Reply) (Parent) (Thread)
[User Picture]
From:totherme
Date:October 11th, 2006 03:42 pm (UTC)
(Link)
If we're going to get geeky/formal about it.... ;)

data Social = Pub 
            | Curry 
            | Ordering Social Social
              deriving (Eq, Show)

pre :: Social -> Social -> Social
pre x y = Ordering y x


Which allows us to do the original thing (remove the parens), so long as we have access to $ and flip:

Main> flip pre Pub $ pre Pub Curry 
Ordering Pub (Ordering Curry Pub)


...which is (one reason) why haskell doesn't have all those brackets :)

As for your "pre pre pre curry pub pub pre curry pre curry pub pub" thing - I notice (with a little help from hugs, I'm afraid) that there are 7 Socials in the phrase, and only 5 "pre" statements... Since every pre takes two Socials and returns one Social, and our goal is to have one Social, we need n-1 "pre"s for every "n" Socials...

So, not ambiguous, certainly confusing, and unfortunately not well formed :/
(Reply) (Parent) (Thread)
[User Picture]
From:totherme
Date:October 11th, 2006 03:53 pm (UTC)
(Link)
Oh - it's possibly worth noting that "pub pre pre pub curry" does an implicit flip of the type I showed here - it's not (just) the infixing that makes it work, it's (also) a redefinition of pre := flip pre.

I was going to say that the infixing just makes it obvious that it doesn't parse any other way. Unfortunately, it does parse another way:
Main> pre Pub (pre Pub Curry)
Ordering (Ordering Curry Pub) Pub

Perhaps it's that we're assuming that one has no need for pre Pub Pub, since one's already in the Pub. Or perhaps there's some weird rule about how native english speakers flip this arguments of their functions when they turn them infix...
(Reply) (Parent) (Thread)
[User Picture]
From:pozorvlak
Date:October 11th, 2006 04:11 pm (UTC)
(Link)
Damn, you're right. Remove the final "pub", and I think we're in business.

I'm well impressed with you writing a subsys-evening-out parser so quickly, though :-)
(Reply) (Parent) (Thread)
[User Picture]
From:totherme
Date:October 12th, 2006 09:57 am (UTC)
(Link)
Yup - here we go :)
Main> pre (pre (pre Curry Pub) Pub) (pre Curry (pre Curry Pub))
Ordering (Ordering (Ordering Pub Curry) Curry) (Ordering Pub (Ordering Pub Curry))


...and I think that is a unique legal parsing. Haskell won't find it for me by default though, because it's more useful to have
pre pre -> _|_
than do embark on a search of possible application orders till you find one that works. Perhaps perl 7 will do that though ;)

Oh - and I didn't write a parser - just a type and a function, as you see above. All the parsing you see here was done either by hugs trying to evaluate expressions containing that function, or by hand. Or a sort of trial and error combination of the two. I actually tried about three paren-combinations before realising that the previous expression was invalid for example ;)

Does this count as a night-out DSL implemented in haskell?
(Reply) (Parent) (Thread)