#:g1: dylanでL-99 (P06 シーケンスが回文的かを判定)

Posted 2008-05-13 13:00:00 GMT

-(http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)
比較の=は、CLでいうequalみたいなもので、==だとeqになる様子。
doは、CLのmapc、Schemeのfor-each。

let lst = #(x:, a:, m:, a:, x:);
let str = "xamax";
let vec = #[x:, a:, m:, a:, x:, a:];

do (method (x) format-out("%= => %=\n", x, x.palindrome?) end, list(lst, str, vec)); //>>> // #(#"x", #"a", #"m", #"a", #"x") => #t // "xamax" => #t // #[#"x", #"a", #"m", #"a", #"x", #"a"] => #f

// code module: l99-06

define generic palindrome? (sequence :: <sequence>) => (result :: <boolean>);

define method palindrome? (sequence :: <sequence>) => (result :: <boolean>) (sequence = sequence.reverse) end method palindrome?;

comments powered by Disqus