Re: Safe pattern matching

2013-02-09 Thread Ian Price
> the nearest analogue to read is object->string, but it is not a generic. That should be string->object. It's funny how often I mix up a->b and b->a -- Ian Price -- shift-reset.com "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy

Re: Safe pattern matching

2013-02-09 Thread Ian Price
Nikita Karetnikov writes: > How would you rewrite the following function in Guile? > > foo :: [Int] -> String -> [Int] > foo (x:y:ys) "+" = (x + y):ys > foo (x:y:ys) "-" = (x - y):ys > foo xs num = read num:xs Daniel covered most of this already, but instead you might consider (define foo

Re: Safe pattern matching

2013-02-09 Thread Daniel Hartwig
On 9 February 2013 18:12, Daniel Hartwig wrote: > Using symbols and literals, rather than strings: Though strings work just as well as symbols :-)

Re: Safe pattern matching

2013-02-09 Thread Daniel Hartwig
On 9 February 2013 17:57, Nikita Karetnikov wrote: > Any Haskellers here? > > How would you rewrite the following function in Guile? > > foo :: [Int] -> String -> [Int] > foo (x:y:ys) "+" = (x + y):ys > foo (x:y:ys) "-" = (x - y):ys > foo xs num = read num:xs Indeed, match can do this. The

Safe pattern matching

2013-02-09 Thread Nikita Karetnikov
Any Haskellers here? How would you rewrite the following function in Guile? foo :: [Int] -> String -> [Int] foo (x:y:ys) "+" = (x + y):ys foo (x:y:ys) "-" = (x - y):ys foo xs num = read num:xs *Main> foo [] "42" [42] *Main> foo [1,2] "42" [42,1,2] *Main> foo [1,2] "+" [3] *Main> foo [1..10