How to reverse a string
|
|
|
Comments (14)
Whenever I compare doing something in bash and doing it in python... It amazes me that people still use non-python for scripting:
~Jeff
text = raw_input("Enter a string: ")
print text[::-1]~Jeff
So why not just make Python your shell?
Because it's scaly and slimy. But so pretty designs obviated by it's propensity to bite so fiercely.
Any other questions, My August Gus III?
Any other questions, My August Gus III?
What about Perl as a shell?
The Python way is very smart, one may agree we cannot learn all languages however. It was just funny to play with on a Saturday.
as in the original article:
echo "linux and life" | rev
pfft. who needs python for this?
Of course, if you want to do complicated arbitrary string handling, something other than a standard unix shell might be in order.
Edit: Much as I appreciate the precision of python, I can't seem to cozy up to it, while perl just feels right.
echo "linux and life" | rev
pfft. who needs python for this?
Of course, if you want to do complicated arbitrary string handling, something other than a standard unix shell might be in order.
Edit: Much as I appreciate the precision of python, I can't seem to cozy up to it, while perl just feels right.
@nmset
>> export z="linux and life";i=0;while [ $i -lt ${#z} ]; do c=${z:i:1}; r=$c$r; i=$((i+1));done; echo $r; unset r; unset i; unset z
That seems a bit cchaotic. Just for fun, I wonder how it would appear in organized emacs-lisp? Some think that Emacs itself is its own compiler, OS and shell...
2c
>> export z="linux and life";i=0;while [ $i -lt ${#z} ]; do c=${z:i:1}; r=$c$r; i=$((i+1));done; echo $r; unset r; unset i; unset z
That seems a bit cchaotic. Just for fun, I wonder how it would appear in organized emacs-lisp? Some think that Emacs itself is its own compiler, OS and shell...
2c
Quoting:Some think that Emacs itself is its own compiler, OS and shell...Because it is. Being written in Lisp makes possible a lot of advantages, including being a platform for developing its own extensions, then attaching them for use, without having to exit and re-start. I know, not every Lisp program can do all that, but if you're going to develop an editor in Lisp, it only makes sense.
Quoting:Some think that Emacs itself is its own compiler, OS and shell...
Quoting:Because it is.
Its own compiler and shell, yes. Its own OS, no.
can't help with emacs lisp, but here is the common lisp version:
or doing it manually:
find examples in countless other languages on rosettacode: http://rosettacode.org/wiki/Reverse_a_string (emacs lisp is there too)
greetings, eMBee
(reverse "linux and life") "efil dna xunil"
(let ((result))
(loop for char across "linux and life"
do (push char result))
(coerce result 'string))
"efil dna xunil"
find examples in countless other languages on rosettacode: http://rosettacode.org/wiki/Reverse_a_string (emacs lisp is there too)
greetings, eMBee
Quoting:Its own compiler and shell, yes. Its own OS, no.Hey, if Firefox is now an OS, can Emacs be far behind?
Quoting:Hey, if Firefox is now an OS, can Emacs be far behind?
Sure, that's possible. Don't get me wrong. Emacs is one helluva program. But its own OS it's not. Not yet, anyway.
someone tried running emacs on a bare kernel: http://www.informatimago.com/linux/emacs-on-user-mode-linux....
FirefoxOS also uses the linux kernel.
neither solution goes as far as SqueakNOS which runs squeak on bare hardware.
greetings, eMBee.
FirefoxOS also uses the linux kernel.
neither solution goes as far as SqueakNOS which runs squeak on bare hardware.
greetings, eMBee.
Post a comment
A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.
Your message:Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help
Sign up and post (it is free) or Log in and post

export z="linux and life";i=0;while [ $i -lt ${#z} ]; do c=${z:i:1}; r=$c$r; i=$((i+1));done; echo $r; unset r; unset i; unset z
No external dependency required.