Just some quickies: Mike has this: fun get_suffix(fn:string) = { var fname = fn; var suffix = ""; match rfind (fname, "?") with | Some ?pos => { suffix = fname.[pos + 1 to]; fname=fname.[0 to pos]; } | None[int] => { match rfind (fname, ".") with | None[int] => {} | Some ?pos => { suffix = fname.[pos + 1 to]; } endmatch; } endmatch; return suffix; }
which is perfectly valid: calculate a closure then execute it. But Felix now has statement matches so you can write this too: fun get_suffix(fn:string) = { var fname = fn; var suffix = ""; match rfind (fname, "?") with | Some ?pos => suffix = fname.[pos + 1 to]; fname=fname.[0 to pos]; | None[int] => match rfind (fname, ".") with | None[int] => {}; | Some ?pos => suffix = fname.[pos + 1 to]; endmatch; endmatch; return suffix; } But then, we could get more functional again: fun get_suffix(fn:string) => match rfind (fn, "?") with | Some ?pos => fn.[pos + 1 to]; | None[int] => match rfind (fn, ".") with | None[int] => "" | Some ?pos => fn.[pos + 1 to] endmatch endmatch ; Noting the assignment to fname in the first match case is useless, we're able to drop the fname variable and just use fn. As a curiosity, this could be done as so: match find_last_of(fn,".?") with | Some ?pos => fn.[p[os + 1 to] | None => "" since find_last_of searches for any of the characters in the second argument, whereas rfind searches for the whole string as a substring. [The C++Standard is clear but the description is a bit hard to deciper] BTW: I'm not a style nazi, but the recommended style for Felix is 2 character indent, including for continuation lines. This is useful in narrow format documentation such as books, web pages, etc. If you want to line function arguments up do this: fun long_name ( arg1:t1, arg2:t2 ) rather than this: fun long_name (arg1:t2 arg2,t2) The latter style cannot work unless the font is monospaced. [I think it looks ugly too, because you have blocks starting all over the place] Another useful hint: for long string quotations: val x = """the quick brown fox jumped over the greasy hog"""; looks horrible. You can do this: val x = "the quick brown \n" "fox jumped over \n" "greasy hog" ; without performance hit (the strings are folded by the compiler early in the compilation process). You can also do this: macro val nl = "\n"; val x = "the quick brown " nl "fox .... with the same result. If you do this: val nl = "\n"; instead, the result will be the same but the concatenation might happen at run time (not sure!). Another useful hint: If you want to write code with prefix functional notation .. try Scheme :) C uses a mix of prefix, postfix, and infix notation, and so does Felix. However Felix is cleaner: * you don't need to write f(x) to call a function, f x will do for the innermost application. In Felix operator whitespace is left associative so f g x means (f g) x and you may need to write f (g x) if that's what you want. * if you can write f x, you can write x.f which again reduces the need for parens: f x.g or even x.g.f as if they were method calls. This works with tuples and (should work with almost) everything else too: f (1,2) ==> (1,2).f Operator . has a higher precedence that whitespace. If you need to factor an expression: val k = x + y * z you can write: val a = y * z; val k = x + a; but this leaves the temporary accessible. Another way that doesn't require any statements is: val k = let ?a = y * z in x + a; The LHS of a let binder, ?a here, is an arbitrary pattern, so you can write val two = 1,2; val second = let _,?second = two in second; as well. You can even write: val maybe = Some 100; val cent = let Some ?x = maybe in x; if you're sure the None case can't occur (if it does you get a run time error). let is just a single case match: val cent = match maybe with | Some ?x => x endmatch; You can also leave the "endmatch" off in an expression if there's no ambiguity (but NOT in a statement match): val cent = match maybe with | Some ?x => x; Similarly you can leave off the endif if there's no ambiguity: var y = if x == 2 then 1 else 20; -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language