Questions

  1. Run the following code,  both interpreted and compiled.
      mycode: [prnt "Hello" halt]
do mycode

Explain the results. 

  1. Rewrite the first do example in this chapter with does.
  2. What is the difference between the has1 and has2 functions in the following code?
      has1: has [][
num: 108 - 42
print num
]

has2: has [num][
num: 108 - 42
print num
]
  1. What are the values of num1 and num2 after executing the following code? Explain.
      ex-glob: function [
/extern num1 ]
[
num1: 13
num2:
42
]

num1: 100 ;== 100
num2: 200 ;== 200
ex-glob
  1. Define a sum function that sums two numbers, n and m. Use argument typing.
  2. Write a testref function that takes two number parameters. The function should have a /add  refinement that returns their sum, and a  /sub  refinement that returns their subtraction.
  3. Write an average function that takes a series of numbers and returns its average.
  1. Red has a built-in sqrt function to calculate the square root of a number. For a negative argument, the mathematical result is a complex number. In Red, this function returns NaN (Not a Number): sqrt -4  ;== 1.#NaN. Write your own mysqrt function that uses sqrt, but guards against a negative input argument with unless. Also make sure that the input is a number! Test all kinds of input.
  2. Fully implement all guards for the fact function mentioned in the section on recursive functions.
  3. Make a car object that contains fields such as brand, selling price, VAT (or discount) percentage, and number of cars in stock. The object should also contain a function that calculates the total price with VAT included, and a function that calculates the total stock value. Make a more concrete object, such as, for example bmw or tesla, and test the object by calling the functions.
  4. Adapt the on-change function in person1 so that the name value cannot be changed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.194.170