Define default values for function arguments

If you want named arguments and default values like PHP or Python, you can call your function with a table constructor: myfunction{a,b=3,c=2} (This is seen in many places in Lua, such as the advanced forms of LuaSocket’s protocol modules and constructors in IUPLua.) The function itself could have a signature like this: function myfunction(t) setmetatable(t,{__index={b=7, … Read more

Static function variables in Swift

I don’t think Swift supports static variable without having it attached to a class/struct. Try declaring a private struct with static variable. func foo() -> Int { struct Holder { static var timesCalled = 0 } Holder.timesCalled += 1 return Holder.timesCalled } 7> foo() $R0: Int = 1 8> foo() $R1: Int = 2 9> … Read more

Table name as a PostgreSQL function parameter

Before you go there: for only few, known tables names, it’s typically simpler to avoid dynamic SQL and spell out the few code variants in separate functions or in a CASE construct. That said, what you are trying to achieve can be simplified and improved: CREATE OR REPLACE FUNCTION some_f(_tbl regclass, OUT result integer) LANGUAGE … Read more

Why can’t ‘kotlin.Result’ be used as a return type?

From the Kotlin KEEP: The rationale behind these limitations is that future versions of Kotlin may expand and/or change semantics of functions that return Result type and null-safety operators may change their semantics when used on values of Result type. In order to avoid breaking existing code in the future releases of Kotin and leave … Read more

What are the problems that are mitigated by not allowing nested function declarations in Go?

I think there are 3 reasons why this obvious feature isn’t allowed It would complicate the compiler slightly. At the moment the compiler knows all functions are at the top level. It would make a new class of programmer error – you could refactor something and accidentally nest some functions. Having a different syntax for … Read more

How to create default value for function argument in Clojure

A function can have multiple signatures if the signatures differ in arity. You can use that to supply default values. (defn string->integer ([s] (string->integer s 10)) ([s base] (Integer/parseInt s base))) Note that assuming false and nil are both considered non-values, (if (nil? base) 10 base) could be shortened to (if base base 10), or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)