combinators

Python implementation of Parsec?

I recently wrote a parser in Python using Ply (it's a python reimplementation of yacc). When I was almost done with the parser I discovered that the grammar I need to parse requires me to do some look up during parsing to inform the lexer. Without doing a look up to inform the lexer I cannot correctly parse the strings in the language....

Good explanation of "Combinators" (For non mathematicians)

Anyone got a good explanation of "combinators" (Y-combinators etc. and NOT the company) I'm looking for one for the practical programmer who understands recursion and higher-order functions, but doesn't have a strong theory or math background. (Note that I'm talking about these things : http://en.wikipedia.org/wiki/Y_combinator ) ...

Scala combinator parsers - distinguish between number strings and variable strings

Hi, I'm doing Cay Horstmann's combinator parser exercises, I wonder about the best way to distinguish between strings that represent numbers and strings that represent variables in a match statement: def factor: Parser[ExprTree] = (wholeNumber | "(" ~ expr ~ ")" | ident) ^^ { case a: wholeNumber => Number(a.toInt) case a: Stri...

Impementation of the Ruby <=> Combinator

Not infrequently, one wants to implement the <=> (comparison, or "spaceship") operator on a product data type, i.e., a class with multiple fields (all of which (we hope!) already have <=> implemented), comparing the fields in a certain order. def <=>(o) f1 < o.f1 && (return -1) f1 > o.f1 && (return 1) f2 < o.f2 && (return -...

How do I get the sum of all content when parsing an XML tag in Ruby?

I have some XHTML (but really any XML will do) like this: <h1> Hello<span class='punctuation'>,</span> <span class='noun'>World<span class='punctuation'>!</span> </h1> How do I get the full content of the <h1/> as a String in Ruby? As in: assert_equal "Hello, World!", h1_node.some_method_that_aggregates_all_content Do any of t...

Combinator logic axioms

I'm carrying out some experiments in theorem proving with combinator logic, which is looking promising, but there's one stumbling block: it has been pointed out that in combinator logic it is true that e.g. I = SKK but this is not a theorem, it has to be added as an axiom. Does anyone know of a complete list of the axioms that need to be...

parser combinator: how to terminate repetition on keyword

I'm trying to figure out how to terminate a repetition of words using a keyword. An example: class CAQueryLanguage extends JavaTokenParsers { def expression = ("START" ~ words ~ "END") ^^ { x => println("expression: " + x); x } def words = rep(word) ^^ { x => println("words: " + x) x } ...

Are these two combinators already available in Haskell?

I need binary combinators of the type (a -> Bool) -> (a -> Bool) -> a -> Bool or maybe [a -> Bool] -> a -> Bool (though this would just be the foldr1 of the first, and I usually only need to combine two boolean functions.) Are these built-in? If not, the implementation is simple: both f g x = f x && g x either f g x = f x || g...

Scala: Can I nudge a combinator parser to be locally greedy?

Suppose I have an ambiguous language expressed in combinator parser. Is there a way to make certain expressions locally greedy? Here's an example of what I mean. import scala.util.parsing.combinator._ object Example extends JavaTokenParsers { def obj: Parser[Any] = (shortchain | longchain) ~ anyrep def longchain: Parser[Any] = zer...

Role of Combinators in Concatenative/Tacit Programming Languages.

Hi! I have a question about what exact role do higher-order combinators (or function producers) hold in concatenative/tacit programming. Additionally I would like to ask if there is another way to implement concatenative programming language rather than directly manipulating the stack. This might look like a newbie question, so if yo...

U combinator on a fibonacci : how would you translate this code to python?

Hi, I am trying to learn about combinators and I am having trouble understand the example given at (Y overriding self-application). I think I am beginning to grasp the concept but I am still far from understanding. I would like to translate the following code to Python: (define (U f) (f f)) (define (fib-nr f) (lambda...

How to create a lazy-seq generating, anonymous recursive function in Clojure?

Edit: I discovered a partial answer to my own question in the process of writing this, but I think it can easily be improved upon so I will post it anyway. Maybe there's a better solution out there? I am looking for an easy way to define recursive functions in a let form without resorting to letfn. This is probably an unreasonable reque...

Combinator logic and unification

Summary: if we are trying to use combinator logic to solve first-order logic type problems, is the best method to feed in free variables and use the standard first-order unification algorithm? In standard first-order logic, consider the problem of deducing that the following is a contradiction p(x) ~p(5) By the rule that we can subst...