Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:52:22+00:00 2026-06-12T08:52:22+00:00

Reading http://www.scala-lang.org/docu/files/ScalaByExample.pdf This piece of code : def While (p: => Boolean) (s: =>

  • 0

Reading http://www.scala-lang.org/docu/files/ScalaByExample.pdf

This piece of code :

def While (p: => Boolean) (s: => Unit) {
  if (p) { s ; While(p)(s) }
}

Is given this explanation :

The While function takes as first parameter a test function, which
takes no parameters and yields a boolean value. As second parameter it
takes a command function which also takes no parameters and yields a
result of type Unit. While invokes the command function as long as the
test function yields true.

Where is if (p) evaluated to true or false ?

Should the function s not be declared somewhere ? There is no code for function s ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:52:24+00:00Added an answer on June 12, 2026 at 8:52 am

    Where is if (p) evaluated to true or false ?

    Exactly there, in that line.

    p and s are call-by-name parameters, because of the => in front of them in the parameter lists of the method While. Every time their name is used in the body of While, they are evaluated.

    Should the function s not be declared somewhere ? There is no code for function s ?

    s is a parameter to the While method, just like p. (Why are you asking this question about s, but not about p?). Methods and functions in Scala can have multiple parameter lists. The While method has two parameter lists.

    You call this While method by passing it something that evaluates to Boolean (the parameter p), and a block (the parameter s).

    var i = 0
    While (i < 5) {
      i = i + 1
      println(i)
    }
    

    In this example p is i < 5, a function that evaluates to a Boolean, and s is the block between the { and }.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im reading this page http://www.scala-lang.org/node/137 , I understand what covariance is and lower bounds
Is the current Scala Eclipse plugin ( http://www.scala-lang.org/node/94 ) usable? I keep reading that
I was reading through this: http://www.postgresql.org/about/ And I saw this: An enterprise class database,
While reading http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html , I found that the caching algorithm is more complex than
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
I was reading Code Conventions for Java from http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-137265.html#587 . In that, they have
I was reading this article on Coding Horror: http://www.codinghorror.com/blog/2008/04/setting-up-subversion-on-windows.html I went to the downloads
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
I was reading the code in the following link http://www.cosc.canterbury.ac.nz/tad.takaoka/alg/graphalg/sc.txt I kept bumping into
I was reading http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 and trying to figure out how to continue a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.