Roelof,
Something like this:
(defn palindrome [x]
(if (string? x)
(clojure.string/reverse x)
(into (empty x) (reverse x))))
Alternatively, you may want to consider explicitly using seq on your inputs
when you get them, and using that of the basis of comparison & input to
reverse. If you don't actually care about the concrete sequence type (i.e.
you only want sensible equality semantics after reversing something),
dropping it as soon as possible may be a better strategy.
Take care,
Moe
On Wed, Oct 7, 2015 at 6:51 PM, Roelof Wobben <[email protected]>
wrote:
> Hello,
>
> I try to solve a problem for 4clojure where I have to make a palingdrome
> detector.
>
> So for trying I did this :
>
> (ns fourclojure.core
> (:gen-class))
>
>
> (defn palingdrome [string]
> ( reverse string))
>
> (apply str (palingdrome '( 1 2 3) )) '321'
> (apply str (palingdrome "Roelof" )) "foleoR"
>
> (defn palingdrome2 [string]
> ( reverse string))
>
> (palingdrome2 '( 1 2 3) ) ( 3 2 1 )
> (palingdrome2 "Roelof" ) (\f \o \l \e \o \R)
>
> So it works for a map or for a string.
>
> Is there a way I can make it work for both ?
>
> Roelof
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.