The Talk Constants And Variables In Erlang
mitnk: Hi, I'm new to Erlang. Can anybody show me how to define a global like variable in Erlang? I wrote like this, http://codepad.org/kSMIyRyc But it got compile Errors.
Erlang: Python code- 18 lines - codepad (0.02s)
dottedmag: mitnk: you don't
dottedmag: mitnk: there are no variables in Erlang, just constants. If you need a constant, just declare arg-less function.
DeadZen: there are variables in erlang.
dottedmag: DeadZen: if you count ETS as variables.
DeadZen: no im counting immutable variables as variables
dottedmag: They aren't _var_iables, they don't vary, right?
DeadZen: and there are mutable variables beyond just ets..
DeadZen: yes they do vary
DeadZen: they don't mutate.
mitnk: How to define and constant? I'm going to look at arg-less
dottedmag: mitnk: my_age/0
DeadZen: variables have different values. thats why they're called variables.. not because a single variables value varies
DeadZen: thats why they're called immutable variables not immutable constants
mitnk: dottedmag: It was in my code.
dottedmag: mitnk: that's the arg-less function.
dottedmag: DeadZen: "immutable variables" is oxymoron
DeadZen: not really... immutable variables and immutable flags are long standing terms
mitnk: dottedmag: Then what you mean by saying "If you need a constant, just declare arg-less function."
dottedmag: mitnk: my_age/0 is constant. So you have already declared it.
DeadZen: but thats not a variable my_age is a function
DeadZen: i thought the question was global variables
mitnk: Ok, thx. Yeah, I meant constant rather than global varmy mistake.
DeadZen: in erlang the question becomes global to what?
DeadZen: global to that process? that node? that cluster?
dottedmag: mitnk: There's another way to do it: http://www.erlang.org/doc/reference_manual/macros.html
Erlang: Erlang -- The Preprocessor (0.86s)
DeadZen: mitnk: -define(MY_AGE, 18). after -export
dottedmag: mitnk: see the 8.2
DeadZen: mitnk: then reference ?MY_AGE in bar()
mitnk: DeadZen: Well, I am writing a simple Sequential program. Maybe I asked a bad question.
DeadZen: mitnk: I don't believe in bad questions, even asking the wrong question is useful indication
DeadZen: mitnk: the subsequent question is always... now what are you trying to do?
mitnk: DeadZen: "-define(MY_AGE, 18)" seems just what I am looking for
DeadZen: dottedmag: also i still assert 1 allowed mutation constitutes a variable.
DeadZen: dottedmag: albeit with limited assignment variability?;p
dottedmag: There is no mutation or assignment -- just coming to scope with defined value.
DeadZen: well thats really what erlang is saying.. once a variable is set, its no longer safe to change it
DeadZen: the value can vary, but not be reassigned
dottedmag: Different instances of the same, ahem, variable may exist with different values in different scopes, but the every particular example is immutable and does not vary.
dottedmag: But that's just the terminology.
dottedmag: So let's agree we describe the same situation using different terms.
DeadZen: thats interesting you consider it not setting a variable but brining a non variable to scope
DeadZen: dottedmag: its 6am, i haven't slept, semantic death is imminent
dottedmag: good night
DeadZen: nah its funny, i had the same thought but arrived at the opposite conclusion
DeadZen: A=1. simple a variable A set to 1.. B = A. a variable B set to the variable A.. the values could be anything.. ergo. they're variables
mitnk: DeadZen: Bye, thx!
DeadZen: mitnk: you're welcome, keep at it
mitnk: dottedmag: I knew variable in Erlang is different. But in book "Programming Erlang", Joe call them variables
DeadZen: if it makes you feel better, we can call them predictable variables
ttmrichter: mitnk: They are variables.
ttmrichter: In the mathematical sense of the term.
ttmrichter: If you think about it, the statement "x = x + 1" is ludicrous.
ttmrichter: It cannot be possible in anything except the most neurotic of number systems (a number system which has one value and is a ring).
ttmrichter: had a massive shock on first contact with BASIC back in the day when seeing "A = A + 1".
ttmrichter: It just didn't make any damned sense.
Erlang: does not compute
mitnk: Thank you, ttmrichter. That's can be right, but my question (concern) here is not this. Thanks all!
ski_: mitnk : your pasted code works fine, if you lift the call to my_age/0 out of the condition
ski_: ponders using a parameterized module for this ..
mitnk: ski_: Yes, I tried that. But I don't want create an extra variable; -define is just the case
ttmrichter: ski_: Parameterized modules are evil.
ski_: ttmrichter : i'm not convinced
ski_: mitnk : nod, then go with that
DeadZen: draws horns on parameterized modules
DeadZen: adds a picture of rush limbaugh
DeadZen: ski_: k... how bout now?
Licenser: ski_ there is a very good explemation why somewhere on the interwerbs let ne dig it out
Erlang: ferd.ca -> YOU WILL REGRET THIS (0.22s)
Licenser: that one, realy worth looking at, not only opend it my eyes but ti made me laugh a lot
nox: when was released -callback attributes?
ski_: DeadZen : all lies !
ski_: (though i suppose horns is a biblical symbol for power ..)
DeadZen: nox: r15 i think
DeadZen: ski_: WITCH!
nox: DeadZen: thanks