Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Problem w/ FP

Name: Anonymous 2012-02-09 22:49

Functional programing makes simple things nearly imposible to do . for example I found this exercise on reddit

"create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format:
your name is (blank), you are (blank) years old, and your username is (blank)
for extra credit, have the program log this information in a file to be accessed later."

At first I dismissed it as stupidly trivial but then thought, is there even a way to do this in scheme? And I couldnt think of one. This just shows that scheme sucks for programs used by users. There is no sequential steps to actually accomplish anything

Name: Anonymous 2012-02-09 23:18

Wow, I'm surprised, this is pretty trivial in scheme. The only thing that's a little difficult is the file io, not because of functional style, but because it is different from C,C++,Java, and it I don't use file io with scheme very often. I'll have to look it up again.


;; for-each is a built in on my scheme implementation.
;(define (for-each operator lis)
;  (if (not (null? lis))
;    (begin (operator (car lis))
;           (for-each operator (cdr lis)))))

(define (print-user-info name age reddit-username)
  (for-each display (list "your name is " name ", you are " age " years old, and your username is " reddit-username))
  (newline))

(define (main log-file)
  (let* ((name (begin (display "Please enter your name: ") (read)))
         (age  (begin (display "Please enter your age: ") (read)))
         (reddit-username (begin (display "Please enter your reddit user name: ") (read))))
    (print-user-info name age reddit-username)
    ;(save-user-info-to-log-file log-file name age reddit-user-name) ;; Lemme look up scheme file io again...
    ))

(main #f)



(load "read.scm")
;loading read.scm
Please enter your name: timmy
Please enter your age: 5634
Please enter your reddit user name: ti_mmy
your name is timmy, you are 5634 years old, and your username is ti_mmy
;done loading read.scm
#<unspecified>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List