Help for a newbie? 
Author Message
 Help for a newbie?

Hello there. I've just started learning Scheme as part of my final year
at college and I have a few questions:

1. Is there a beginner->advanced on-line manual/tutorial I can look at?
2. What book is best for learning Scheme?
3. How do I make blocked if..then..else statements in Scheme? E.g.:

if (condition) {
        ...
        ...

Quote:
}

else {
        ..
        ..

Quote:
}

TIA

Johnny

--
"Life is like a dog sled team:  if you ain't the lead dog, the scenery
never changes."



Mon, 18 Mar 2002 03:00:00 GMT  
 Help for a newbie?
Hello Johnny,

Quote:
> 1. Is there a beginner->advanced on-line manual/tutorial I can look at?

Try http://www.cs.rice.edu/~dorai/t-y-scheme/t-y-scheme.html
If find it very good.

Quote:
> 2. What book is best for learning Scheme?

I've heard that the "The little schemer" is good. The holy bible is
"Structure and Interpretation of Computer Programs" aka SICP.

Quote:
> 3. How do I make blocked if..then..else statements in Scheme? E.g.:

> if (condition) {
>    ...
>    ...
> }
> else {
>    ..
>    ..
> }

Simple:
(if cond
    expr
    else-expr)

Bye.

(lambda (msg)
  (case msg
        ((name)         "Miki Tebeka")

        ((homepage)     "http://www.tebeka.freeservers.com")
        ((quote)        "All computers wait at the same speed")))



Mon, 18 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:

> > 3. How do I make blocked if..then..else statements in Scheme? E.g.:

> > if (condition) {
> >       ...
> >       ...
> > }
> > else {
> >       ..
> >       ..
> > }

> Simple:
> (if cond
>     expr
>     else-expr)

What happens here then?

(if (null? (list))
        (display "Null List")
        (display "Not Null List")
)

Assuming this prints out "Null List" if the x is a null list (e.g. ())
and "Not Null List" if the list is not null (e.g. (car x) returns
_something_), how would I do an if..then..else such that in C or Java
this would work. This would be:

(if x.length==0) {
        System.out.println("Null list");

Quote:
}

else {
        System.out.println("Not null list");

Quote:
}

And short of doing:

(if (null? (list)))
        (display "Null List")
)
(if (not (null? (list)))
        (display "Not null list")
)

How can I do this?

--
Johnny Ooi. Aliases: Loopy, Tuxedo Mask, Quote Master.....

WWW             : http://www.dcs.qmw.ac.uk/~jjyooi/
ICQ No          : 6155774

"Stay sane guys!"

===============================================================



Mon, 18 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:

> What happens here then?

> (if (null? (list))
>         (display "Null List")
>         (display "Not Null List")
> )

I believe that you want to say

(if (null? list)
    (display "Null List")
    (display "Not Null List")
)

unless "list" is a procedure that takes no arguments.  Any time Scheme
evaluates an expression of the form
    (expr1 ... exprn)
it assumes expr1 is a procedure.  In other words, extra parenthesis are not
a good thing.

--
Best Regards,
  Bob McGrail

****************************************************

By virtue knowledge

****************************************************
Bard College
Division of Natural Science and Mathematics
P.O. Box 5000
Annandale-on-Hudson, NY 12504

Phone:  (914) 758-7265

Web:  inside.bard.edu/~mcgrail



Mon, 18 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:

> > What happens here then?

> > (if (null? (list))
> >         (display "Null List")
> >         (display "Not Null List")
> > )

> I believe that you want to say

> (if (null? list)
>     (display "Null List")
>     (display "Not Null List")
> )

> unless "list" is a procedure that takes no arguments.

... which it is.  Unless you rebind LIST, it takes any
number of arguments and returns a list.  Thus (LIST)
is always NULL?.

--

Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
         ---  Food, Shelter, Source code.  ---



Mon, 18 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:


> > I believe that you want to say

> > (if (null? list)
> >     (display "Null List")
> >     (display "Not Null List")
> > )

Maybe it might become clearer if I write it this way:

(define (isnull x)
        (if (null? x)
                (display "Null")
                (display "Not Null")
        ))
)

Now if I do:

(define temp (list))

So that temp is now an empty list "()" and then pass it to isnull like
so:

(isnull temp)

I want it to return "Null"

If on the other hand, I defined temp like so:

(define temp (list 1 2 3))

So that it is now the list (1 2 3), I want isnull to return "Not Null"

On top of that, how could I do something like this (this is Java and I'm
using Vectors instead of lists):

public void isnull (Vector v) {
        if (v.size()==0) {
                System.out.println("This vector is empty");
        }
        else {
                System.out.println("This vector is not empty.");
                System.out.println(v)
        }

Quote:
}

My point is I know that the structure of an if clause is:

( if (cond)
        if-cond
        else-cond
)

But how can I make several lines for the if-cond or the else-cond.
Namely:

(if (cond)
        if-cond
        if-cond
        if-cond
        else-cond
)

Or isn't it possible? The only way I know is to make several if's each
one with the same condition so that if one matches, Scheme is guaranteed
to do all the others as well.

--
Johnny Ooi. Aliases: Loopy, Tuxedo Mask, Quote Master.....

WWW             : http://www.dcs.qmw.ac.uk/~jjyooi/
ICQ No          : 6155774

"Stay sane guys!"

===============================================================



Tue, 19 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:

> But how can I make several lines for the if-cond or the else-cond.
> Namely:

> (if (cond)
>         if-cond
>         if-cond
>         if-cond
>         else-cond
> )

(if (cond)
        (begin
                line-1
                line-2
                line-3
        )

should do the job, if I understand you correctly

Regards
Friedrich



Tue, 19 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:

> > But how can I make several lines for the if-cond or the else-cond.
> > Namely:

> > (if (cond)
> >         if-cond
> >         if-cond
> >         if-cond
> >         else-cond
> > )

> (if (cond)
>         (begin
>                 line-1
>                 line-2
>                 line-3
>         )

> should do the job, if I understand you correctly

How can I forget about "begin"? I try it out. Thanks for telling. I'll
let you know if there are any more problems.

Johnny



Tue, 19 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:
>But how can I make several lines for the if-cond or the else-cond.
>Namely:

>(if (cond)
>    if-cond
>    if-cond
>    if-cond
>    else-cond
>)

Either like this:

(if (> 2 1)
    (begin
      (display "foo")
      (display "bar")
      (newline))
    (begin
      (display "baz")
      (newline)))

or with a cond, like this:

(cond ((> 2 1)
       (display "foo")
       (display "bar")
       (newline))
      (else
       (display "baz")
       (newline)))

Both work equally well; which one people use seems to be a matter of
taste.

Often you need a local variable in one of the branches. Then it's
useful to remember that there can be many expressions in the body of a
let:

(if (> 2 1)
    (let ((a 2))
      (display "a: ")
      (display a)
      (newline))
    (error "foo"))

You've probably noticed that you don't need multiple expressions in if
statements as often in Scheme than you do in, say, C. If you don't use
side effects (set!, display, etc.), multiple expressions are useless:
you could just leave the first ones out, if they don't have side
effects and the value they compute isn't used. And side effects are
not as necessary in Scheme as they are in imperative languages,
because Scheme supports functional programming.

--



Wed, 20 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:
> My point is I know that the structure of an if clause is:

> ( if (cond)
>  if-cond
>  else-cond
> )

> But how can I make several lines for the if-cond or the else-cond.
> Namely:

> (if (cond)
>  if-cond
>  if-cond
>  if-cond
>  else-cond
> )

If you're trying to do what I think you're trying to do, it would look like:
(if (test)    ; note that "cond" is a reserved word
  (begin
    if-thing1
    if-thing2
    if-thing3)
  (begin
    else-thing1
    else-thing2
    else-thing3))

Also:
(cond
  ((test)
    if-thing1
    if-thing2
    if-thing3)
  (else
    else-thing1
    else-thing2
    else-thing3))

I hope that helps.

--Jed, scheming.

"But life wasn't yes-no, on-off.  Life was shades of gray, and rainbows not
in the order of the spectrum."   -- L. E. Modesitt, Jr., _Adiamante_



Wed, 20 Mar 2002 03:00:00 GMT  
 Help for a newbie?

Quote:

> note that "cond" is a reserved word

I know that -- now! ;-)

--
Johnny Ooi. Aliases: Loopy, Tuxedo Mask, Quote Master.....

WWW             : http://www.dcs.qmw.ac.uk/~jjyooi/
ICQ No          : 6155774

"Stay sane guys!"

===============================================================



Fri, 22 Mar 2002 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Need help with Textreading (Newbie)

2. Help a relative newbie.

3. Help a Smalltalk newbie, please.

4. Help a relative newbie

5. Any help for a newbie using CW 1.0?

6. Help for a newbie in SML !

7. help for rexx newbie and setting background for folder

8. Help a Ruby newbie?

9. Help a keen Newbie

10. Help to a newbie

11. Design Flow Help for a Newbie in Quartus II

12. Help with optimizing newbie code (inline assembly under VC++ 6.0)

 

 
Powered by phpBB® Forum Software