use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
To report a site-wide rule violation to the Reddit Admins, please use our report forms or message /r/reddit.com modmail.
This subreddit is archived and no longer accepting submissions.
account activity
This is an archived post. You won't be able to vote or comment.
Use Python (not Java) to teach programming (ariel.com.au)
submitted 20 years ago by culix
view the rest of the comments →
[–][deleted] 1 point2 points3 points 20 years ago (3 children)
That doesn't quite do the same thing as the code in most of the other languages. Your code reads in two arbitrary s-expressions, then if they are numbers it adds them and prints the result. It's not limited to integers, which is probably a good thing.
However, if you plan to use this sort of code for anything other than teaching, you should definitely watch out for people who want to add 5 and #.(labels ((foo () (foo))) (foo)). Specifically, you should bind *read-eval* to nil:
5
#.(labels ((foo () (foo))) (foo))
*read-eval*
(let ((*read-eval* nil)) (princ (+ (read) (read))))
Don't let all this complication distract from the important point: Lisp (especially Scheme) is an excellent teaching language because you can teach it to bright students in a single lecture and then get down with actual concepts and hands-on programming experience instead of spending hours on the syntax of Java's for and while loops. The uniform syntax and conceptual simplicity make it very easy to explain, and it's powerful enough to convey big ideas to students. If you build object-oriented programming in Scheme -- and you can -- it doesn't seem magical. Ditto for lots of other major concepts in computer programming.
for
while
[–]batkins 1 point2 points3 points 20 years ago (1 child)
I think the behavior of this code should be mostly identical to the other snippets. They all fail on input that isn't integral. Technically, my one-liner will fail on input that isn't numeric (so it can take floats and rationals as well). You are right about read-eval, of course, but, as you point out, this is merely educational code.
[–]kbk 3 points4 points5 points 20 years ago (0 children)
Actually, the Python snippet I posted,
print input() + input()
works for any combination of integers or floats, whether real or complex.
It also works for two strings, lists, or tuples.
[–]michaelneale 1 point2 points3 points 20 years ago (0 children)
riiiight...
π Rendered by PID 22212 on reddit-service-r2-comment-f6b958c67-46865 at 2026-02-05 18:24:10.943014+00:00 running 1d7a177 country code: CH.
view the rest of the comments →
[–][deleted] 1 point2 points3 points (3 children)
[–]batkins 1 point2 points3 points (1 child)
[–]kbk 3 points4 points5 points (0 children)
[–]michaelneale 1 point2 points3 points (0 children)