method from
Contract
Return typewob
Parameter keyDefault valueType
objreq
makefalseboolean
Water Contract
<method from
  obj =req
  make=false/>

See also: to_cxs, to_htm, to_txt

from attempts to turn an object into another kind of object. It is a data-converter and in some cases an alternative way to construct an object from the usual <some_class/> way of making an instance. from uses a whole bunch of heuristics to do conversion. If it can't make a reasonable conversion, it errors. The syntax is: some_type.<from some_object/> from generally accepts many different types for some_object. If some_object is already an instance of some_type, then some_object is just returned. Otherwise, an attempt is made to use some_object as a description of an instance of some_type. If successful, that instance is returned, otherwise error. There are a lot of details to from . If you're confused about what it may do in a certain situation, just try it. In general from does a good job and converting between literals. It also converts to vectors and even record objects.

boolean

false , the integers 0 and -1, the chars 0fFnN, and the strings "false" "null" "no" "" "0" "-1" (of any case) are all converted to false. Everything else is converted to true.
boolean.<from 0/>false
boolean.<from "NO"/>false

integer

null and false are converted to 0. true is converted to 1. integers convert to themselves. Decimals or number.double are converted to the integer immediately above it or below it depending on the 'direction' argument which may be: "nearest" "towards_zero" "up" "down". chars are converted to their ASCII equivalent. strings are read as a string of digits (with optional leading minus sign) Everything else errors.
integer.<from false/>0
integer.<from "123"/>123
integer.<from <char "a"/>/>97
integer.<from 12.3 direction="up"/>
13
integer.from can also take a radix parameter to provide a base for conversion of strings.
integer.<from "A" radix=16/>10

number.double

integers convert to the double-precision number of the same numerical value. double-precision numbers convert to themselves strings are read as a decimal number, usually with a decimal point in them.
number.double.<from 23/>23.0
number.double.<from "23.4"/>23.4
number.double.<from "17"/>17.0
number.double.<from "17."/>17.0
number.double.<from ".1"/>0.1

number

decimals or integers convert to themselves characters convert to their ASCII equivalent integer strings are converted to an integer if they have no decimal point in them, and a number.double if they do.
number.<from <char "a"/>/>97
number.<from "34"/>34
number.<from "3.4"/>3.4
number.from takes a radix argument just like integer.from .

char

An integer is used as the ASCII value to find the corresponding char. A string has its first char returned. If the string is empty, error
char.<from 97/>char.a
char.<from "a"/>char.a

string

to_cxs is called on the argument and the resulting string is returned.
string.<from 123/>"123"
If you have a vector of chars and you want to convert it to a string, you can't use 'from'. Do this instead:
<vector <char "a"/> <char "b"/>/>.<to_htm/>
"ab"

vector

A strings are converted into a vector of chars. Supervectors, i.e. records that contain vector-keys, are converted into a straight vector, losing the information in non-vector keys. vectors are just returned. For other types of objects an empty vector is returned since they have a length of zero.
vector.<from <thing "red" "blue"/>/>
<vector "red" "blue"/>

datetime

Particular strings are converted into a datetime. The strings must follow a special syntax, but this can still make entry of dates easier. Each string argument contains one, two or three integers separated by a dash, slash, comma, period or space. The first integer represents the year [use 4 digits], the 2nd the month [1=jan] the third is the day of the month [1 through 31]. Exception: If you give only two integers and the first integer is less than 13, then the first integer is considered to be the month and the 2nd integer is the day of the month with the year defaulting to the current year.
Example: Returns Dec 25th in the current year
datetime.<from "12-25"/>
Example: Returns a datetime in 2003
datetime.<from "2003/12/25"/>
<datetime 2003 12 25 0 0 0 0/>
thing thing.<from some_obj/> usually just returns some_obj since, after all, everything is a thing so some_obj is already a thing. However there's one exception. If some_obj is a vector, then a new object is made which is an instance of the subject of thing that will contain non-negative consecutive integer keyed fields with their corresponding values from the vector.
thing.<from <vector 4 5/>/>
<thing 0=4 1=5/>
class if converting from a string with no spaces, and the class has an 'of' field, then it will look up an instance by the key.