Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello World exercise not trivial in scheme #34

Closed
PurityControl opened this issue May 22, 2015 · 7 comments · Fixed by #69
Closed

Hello World exercise not trivial in scheme #34

PurityControl opened this issue May 22, 2015 · 7 comments · Fixed by #69

Comments

@PurityControl
Copy link
Contributor

Given the purpose of the hello world exercise, the solution in scheme maybe harder than we would like.

The r5rs specification gives a portable implementation for optional arguments. However use of this, as I understand it, requires knowledge of setting up functions with the more formal definition of a function using lambda and making the arguments to lambda a symbol rather than a list.

That is the traditional

(define (foo x)
  .......)

will no longer work and requires

(define foo
  (lambda x ...........)

this is non intuitive as the lambda form is normally

(define foo
  (lambda (x) .........)

Guile offers a non portable define* which is slightly less confusing but requires users to be familiar with guile's library.

I think it may be worth adding further information to the README with a small explanation and links
to further reference such as

https://www.gnu.org/software/guile/manual/html_node/Optional-Arguments.html

https://www.gnu.org/software/guile/manual/html_node/Lambda.html#Lambda

https://www.gnu.org/software/guile/manual/html_node/lambda_002a-and-define_002a.html#lambda_002a-and-define_002a

@kytrinyx
Copy link
Member

Is there a way to change the exercise to make it trivial? We can always make the README more ambiguous to suit.

@PurityControl
Copy link
Contributor Author

We could either add an explanation that optional arguments are explained in the links above. I think the optional argument exercise is a valuable exercise.

If we feel that even with an explanation it is too much for the initial hello world exercise and would be more suited to a later problem we could ask for two functions to be defined.

  • One function say hello would take no arguments and return "hello world".
  • The second function say greet would take an argument and return a greeting with the argument in.

@canweriotnow
Copy link
Contributor

@kytrinyx The issue is Scheme's treatment of variadic functions, so the easiest change for Scheme would be to make it either arity-0 ("Hello, world!" only) or arity-1 ("Hello, {{arg}}!" only) and not have an optional argument to the function.

Now, as @PurityControl pointed out, there are multiple ways to do variadic functions in Scheme, some specified in R5RS or R6RS, and some implementation-specific; I think it makes Scheme a really interesting track from a high level perspective just to see what people come up with, but for "hello world"... IIRC, Abelson and Sussman don't even throw variadic functions at you until halfway through SICP. I'm open to any changes that seem sensible to everyone, whether that's making the README more vague to allow for wider types of implementation, or putting some more structure in hello-world.scm, or some self-deprecating comments in to the tune of "Hello world should bethe easiest thing in the world, but you picked Scheme, so the joke's on you!"

Okay, maybe not that last one.

@kytrinyx
Copy link
Member

"Hello world should bethe easiest thing in the world, but you picked Scheme, so the joke's on you!"

That totally made me smirk, but yah, maybe not :)

@canweriotnow
Copy link
Contributor

Here's a possibility: Include in the stub:

(define hello
  (λ (name)
    (string-concatenate (list "Hello, " name "!"))))

Include a (already passing) test for that, leaving it to the user to implement:

(define hello-world
  (λ ()
    (hello "World")))

To get the other test to pass. I'm thinking this b/c the point (unless I'm mistaken) is "How do I exercism?" more than "How do I scheme?". The drawback IMHO is that it is non-standard in providing an implementation file with working code in it. But maybe that could be explained in the comments.

Thoughts?

@PurityControl
Copy link
Contributor Author

Seems like a pragmatic solution to me.

@kytrinyx
Copy link
Member

kytrinyx commented Jun 7, 2015

I think it's completely fine to provide an implementation file with working code... it's not a complete solution after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants