Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Scheme Programming Language

If blocks


Can someone explain to me the proper way to code an 'if' statement
when there are multiple lines involved.
For instance in Ruby:

     if x == true
        do_step_one()
        do_step_two()
     else
        do_step_three()
        do_step_four()
     end

How is this properly done on Scheme:

    (if (eqv? x #t)
(if (eqv? x #t)

(begin
((do-step-one)
          (do-step-
one)                                                 (do-step-two))
          (do-step-two))                  or
((do-step-three)

(begin
(do-step-four)))
          (do-step-three)
          (do-step-four)))

Is begin the way to go or does begin have a different (sequencing)
meaning?    And is the other way even
legal?

WoodHacker wrote:
> Can someone explain to me the proper way to code an 'if' statement
> when there are multiple lines involved.
> For instance in Ruby:

>      if x == true
>         do_step_one()
>         do_step_two()
>      else
>         do_step_three()
>         do_step_four()
>      end

(cond
   [x (do-step-one)
      (do-step-two)]
   [else
      (do-step-three)
      (do-step-four)])

> Is begin the way to go or does begin have a different (sequencing)
> meaning?    

With if+begin it looks like:

(if x
     (begin
       (step1)
       (step2))
     (begin
       (step3)
       (step4)))

but I find that harder to read.

--
Jens Axel Sgaard

On Apr 6, 8:03 am, Jens Axel Sgaard <use@soegaard.net> wrote:

Brackets apparently don't work in Chicken Scheme, which is what I'm
using.   It compiles, but I get errors when I run it.    Using cond
seems overkill for such a simple conditional, but it's probably just
as efficient.   Thanks for the help.

Bill

In article <1175949270.113445.280@y80g2000hsf.googlegroups.com>,

 "WoodHacker" <ramsa@comcast.net> wrote:
> On Apr 6, 8:03 am, Jens Axel Sgaard <use@soegaard.net> wrote:
<snip>

> Brackets apparently don't work in Chicken Scheme, which is what I'm
> using.   It compiles, but I get errors when I run it.    Using cond
> seems overkill for such a simple conditional, but it's probably just
> as efficient.   Thanks for the help.

> Bill

What version of Chicken? I think brackets, '[...]', have been legal
syntax since before version 2 (2 years ago). If you see errors then
something else besides syntax is the problem.

cond is usually compiled into nested if forms anyway so efficiency is
more of a programmer time rather than a machine time issue.

Try the Chicken mailing list, chicken-us@nongnu.org, for Chicken
specific questions.

Best Wishes,
Kon

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc