Wouter's Blog

About OPA, Joomla, Agile and other computing related topics

0 notes &

Opa up and running Page 43 gen_page

When trying to build the code on page 43 of the Opa up and running book I ran in to the following error:

Error: File “wiki.opa”, line 27, characters 24-94, (27:24-30:1 | 432-502)
Type Conflict
  (22:0-22:2)         list(string)
  (29:28-29:38)       string

  The second argument of function gen_page should be of type
      string
  instead of
      list(string)

After some searching I found out that the problem is in the function gen_page.

<div class={class}>

In the sample_page function we would like the value of class= to be <div class=container> and this should be all-right. In Opa we should be able to ommit double quotes around strings when values are uninterrupted strings like container. However for some reason, I end up with this typing error. Solution seems to add the quotes like so:

<div class=” {class}” >

Would like to know if this is a bug in OPA and error in the book or I made a mistake?

Filed under opa opaupandrunning programming languages

0 notes &

OPA up and running wrong code example page 48

This is a  bit of a strange first post on my blog. I am learning a new program language OPA, which I will explain further in later post. I am using a book called OPA up and running (bought at Amazon), which I like very much so far. However page 48 has an error. 

the complete code for the guessing game example should be:

function page(){
    secret = 1 + Random.int(10);
    <h1>Guess the number (1-10)?</h1>
    <input id=#guess />
    <span onclick={show(secret,_)}>Check</>
    <div id=#message />
}

function show(secret,_){
    guess = String.to_int(Dom.get_value(#guess));
    message =
        if (guess == secret){ <span class=”succes”>You got it right!</span> }
        else if (guess<secret){<> higher</>}
        else {<>lower</>};
    #message = message;       
}

Server.start(Server.http,
    { title: “Database Demo”, ~page
    }
)

The authors accidentally repeated the code sample on page 46. Good luck.

Filed under opa opaupandrunning programming languages