Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Five Ways to Reverse a String of Words (..., Oz)

by diotalevi (Canon)
on Jan 07, 2007 at 19:41 UTC ( #593427=note: print w/replies, xml ) Need Help??

in reply to Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

For giggles I tried writing this in Oz. The ReverseWords function could have been written without all the intermediate variables but it would have suffered in readability so I didn't. It's also a complete program with loading the appropriate libraries, etc.

functor import Application System String at 'x-oz://system/String.ozf' define fun {IsntNil X} case X of nil then false else true end end fun {ReverseWords In Split} local Tokens FilteredTokens Reversed Str in Tokens = {String.split In Split} FilteredTokens = {List.filter Tokens IsntNil} Reversed = {List.reverse FilteredTokens} Str = {String.join Reversed Split} {String.toAtom Str} end end in {System.print {ReverseWords " one two three four " " "}} {Application.exit 0} end

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: Five Ways to Reverse a String of Words (..., Oz)
by Anonymous Monk on Mar 23, 2007 at 10:16 UTC
    no php yet? no respect! ;)

    $reversed = implode(' ', array_reverse(explode(' ', $str)));

    kept it on one line so the perl guys can understand it :)
      php is the bomb

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://593427]
[shmem]: $list_addiction should be $list_addition
Discipulus loose the tozzetto party!
[shmem]: .oO( addition of cookies for addiction to cookies )
[Lady_Aleena]: Other than my typos shmem. 8)
[shmem]: otherwise fine
[Discipulus]: tozzetti & vinsanto
[Lady_Aleena]: The whole line is push @line, ref($list_addition ) ? @$list_addition : $list_addition if $list_addition;
[Lady_Aleena]: And I forgot to do the array check, I'm such a doofus today.
[Lady_Aleena]: push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addition if $list_addition; #trying again
[shmem]: Discipulus: yummy. I like those. Didn't have them for some time now, forgot the name. Should go get some...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-04-27 11:47 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (503 votes). Check out past polls.