guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Safe pattern matching


From: Ian Price
Subject: Re: Safe pattern matching
Date: Sat, 09 Feb 2013 10:48:34 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Nikita Karetnikov <address@hidden> 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
  (match-lambda* ....))
rather than
(define (foo . args)
   (match args
     ....))

the nearest analogue to read is object->string, but it is not a generic.

-- 
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 Compiled"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]