# \#variable

**URL:** https://forum.elixirforum.com/tag/variable/554.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [Using \`with\` as the Elixir replacement for \`let\` in Lisp](https://forum.elixirforum.com/t/using-with-as-the-elixir-replacement-for-let-in-lisp/68029)

<div class="topic-metadata">

**Author:** [@simonelnahas](https://forum.elixirforum.com/u/simonelnahas)\
**Replies:** 11\
**Last updated:** [December 12, 2024, 7:48pm UTC](https://forum.elixirforum.com/t/using-with-as-the-elixir-replacement-for-let-in-lisp/68029 "2024-12-12T19:48:56Z")

</div>

Coming from Clojure, Haskell, and Ocaml I’m very happy about using let for variable scoping. I have then started using with for this in Elixir, even though the documentation suggests using it to combine case clauses. w…

---

## [When to use a variable vs simple value returning function](https://forum.elixirforum.com/t/when-to-use-a-variable-vs-simple-value-returning-function/37190)

<div class="topic-metadata">

**Author:** [@WestKeys](https://forum.elixirforum.com/u/WestKeys)\
**Replies:** 12\
**Last updated:** [August 3, 2024, 3:27am UTC](https://forum.elixirforum.com/t/when-to-use-a-variable-vs-simple-value-returning-function/37190 "2024-08-03T03:27:23Z")

</div>

Why would we use def table do \[{?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"}\] end Rather than table = \[{?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"}\] In this example defmodule KV.…

---

## [Is an Elixir GenServer so different from an Object of a Class?](https://forum.elixirforum.com/t/is-an-elixir-genserver-so-different-from-an-object-of-a-class/60290)

<div class="topic-metadata">

**Author:** [@mikejm](https://forum.elixirforum.com/u/mikejm)\
**Replies:** 26\
**Last updated:** [December 12, 2023, 7:44pm UTC](https://forum.elixirforum.com/t/is-an-elixir-genserver-so-different-from-an-object-of-a-class/60290 "2023-12-12T19:44:57Z")

</div>

I am just learning Elixir. The purpose is to build a server API to interact between clients and a separate database server. I am coming from C#/C++. I have now been reading a variety of tutorials on GenServer, as that s…

---

## [Share variable with all functions in a module](https://forum.elixirforum.com/t/share-variable-with-all-functions-in-a-module/60212)

<div class="topic-metadata">

**Author:** [@jarvism](https://forum.elixirforum.com/u/jarvism)\
**Replies:** 4\
**Last updated:** [December 6, 2023, 9:55pm UTC](https://forum.elixirforum.com/t/share-variable-with-all-functions-in-a-module/60212 "2023-12-06T21:55:13Z")

</div>

Hello, everyone! I am having a really hard time wrapping my head around this one for some reason. I want to get a token, store it in memory in a module, have it available for all the functions in the module, and update…

---

## [Can anonymous function be called inside of iex](https://forum.elixirforum.com/t/can-anonymous-function-be-called-inside-of-iex/57354)

<div class="topic-metadata">

**Author:** [@Djordjenp](https://forum.elixirforum.com/u/Djordjenp)\
**Replies:** 1\
**Last updated:** [July 31, 2023, 6:23pm UTC](https://forum.elixirforum.com/t/can-anonymous-function-be-called-inside-of-iex/57354 "2023-07-31T18:23:54Z")

</div>

Hello, I am new to elixir and I am trying to call my anonymous function defined in my “ex” file like so: package\_data = fn (x, \[y\]) -\> \[x, y\] (x, 5) -\> x + 20 (x, y) -\> {x, y} end When I compile this file using “…

---

## [List as functions argument never matched](https://forum.elixirforum.com/t/list-as-functions-argument-never-matched/54270)

<div class="topic-metadata">

**Author:** [@rrrr](https://forum.elixirforum.com/u/rrrr)\
**Replies:** 2\
**Last updated:** [March 2, 2023, 3:15pm UTC](https://forum.elixirforum.com/t/list-as-functions-argument-never-matched/54270 "2023-03-02T15:15:59Z")

</div>

I got 2 warnings and “unexpected” behavior when trying to match argument as a list. Is this code incorrect? How can I match a argument as a List? (It’s first code i am writing by myself :innocent: I was trying to be clo…

---

## [Facing Problem while appending elements In a list](https://forum.elixirforum.com/t/facing-problem-while-appending-elements-in-a-list/50770)

<div class="topic-metadata">

**Author:** [@Gupta](https://forum.elixirforum.com/u/Gupta)\
**Replies:** 21\
**Last updated:** [October 16, 2022, 5:24pm UTC](https://forum.elixirforum.com/t/facing-problem-while-appending-elements-in-a-list/50770 "2022-10-16T17:24:12Z")

</div>

I was working on a Question which was , Input - A list of numbers - \[1,2,3,4,5\] example We have to produce the subsets of this list and display those subsets whose sum is equal to 10 Output Format - \[ \[1,2\] , \[2,3\] , …

---

## [Problem While installing Elixir for vs code](https://forum.elixirforum.com/t/problem-while-installing-elixir-for-vs-code/50856)

<div class="topic-metadata">

**Author:** [@Gupta](https://forum.elixirforum.com/u/Gupta)\
**Replies:** 6\
**Last updated:** [October 8, 2022, 4:46pm UTC](https://forum.elixirforum.com/t/problem-while-installing-elixir-for-vs-code/50856 "2022-10-08T16:46:17Z")

</div>

Hi ! I ws as trying to install elixir on my windows so i successfully installed it and i can see my elixir IDE showing on my start menu. Now i was trying to setup my vs code for Elixir so I installed one extension named…

---

## [Getting UndefinedFunctionError for a variable, even after it is well defined](https://forum.elixirforum.com/t/getting-undefinedfunctionerror-for-a-variable-even-after-it-is-well-defined/43186)

<div class="topic-metadata">

**Author:** [@r12543](https://forum.elixirforum.com/u/r12543)\
**Replies:** 5\
**Last updated:** [October 19, 2021, 11:19am UTC](https://forum.elixirforum.com/t/getting-undefinedfunctionerror-for-a-variable-even-after-it-is-well-defined/43186 "2021-10-19T11:19:47Z")

</div>

Hello, I am getting the following error. Code is also mentioned below. %UndefinedFunctionError{arity: 0, function: :offset, message: nil, module: nil, reason: nil} {offset, \_} = Integer.parse(headers\["upload-offset"\])…

---

## [Elixir does not recognize a varibale and extends it as a function. Why does this happen?](https://forum.elixirforum.com/t/elixir-does-not-recognize-a-varibale-and-extends-it-as-a-function-why-does-this-happen/42857)

<div class="topic-metadata">

**Author:** [@code](https://forum.elixirforum.com/u/code)\
**Replies:** 5\
**Last updated:** [October 7, 2021, 2:24pm UTC](https://forum.elixirforum.com/t/elixir-does-not-recognize-a-varibale-and-extends-it-as-a-function-why-does-this-happen/42857 "2021-10-07T14:24:54Z")

</div>

Here is my code: defmodule HW3A do def onepad(int, n \\\\ 0, list \\\\ \[\]) do case n do ^int -\> list \_ -\> onepad(int, n + 1, list ++ \[:rand.uniform(int)\]) end end defp string\_to\_…

---

## [Variables leaking](https://forum.elixirforum.com/t/variables-leaking/31298)

<div class="topic-metadata">

**Author:** [@Hal9000](https://forum.elixirforum.com/u/Hal9000)\
**Replies:** 3\
**Last updated:** [May 7, 2020, 2:33am UTC](https://forum.elixirforum.com/t/variables-leaking/31298 "2020-05-07T02:33:55Z")

</div>

I’ve been thinking about the change made 2-3 years ago where it’s no longer permitted to set variables inside a case statement (or similar). Is it fair to summarize this by saying: Variable values can pass from an out…

---

## [About variables scope](https://forum.elixirforum.com/t/about-variables-scope/30144)

<div class="topic-metadata">

**Author:** [@Sanjibukai](https://forum.elixirforum.com/u/Sanjibukai)\
**Replies:** 18\
**Last updated:** [March 31, 2020, 6:57am UTC](https://forum.elixirforum.com/t/about-variables-scope/30144 "2020-03-31T06:57:09Z")

</div>

Hello everybody, I just noticed something that I admit I should have been notice way more earlier TBH.. Variables are scoped in ifs, conds, cases (and I bet it’s applicable to any block). An example with a simplified …

---

## [Inject variable into macro function body](https://forum.elixirforum.com/t/inject-variable-into-macro-function-body/24314)

<div class="topic-metadata">

**Author:** [@PatrickSachs](https://forum.elixirforum.com/u/PatrickSachs)\
**Replies:** 2\
**Last updated:** [July 31, 2019, 6:58pm UTC](https://forum.elixirforum.com/t/inject-variable-into-macro-function-body/24314 "2019-07-31T18:58:25Z")

</div>

My termininology with the question title is probably all over the place, but I’m really struggling on how to phrase it. What I essentially want to do, is something like plug does in its “get”/“post”, etc. macros: It inj…

---

## [Reference a static variable in function docs](https://forum.elixirforum.com/t/reference-a-static-variable-in-function-docs/19880)

<div class="topic-metadata">

**Author:** [@jeramyRR](https://forum.elixirforum.com/u/jeramyRR)\
**Replies:** 5\
**Last updated:** [February 3, 2019, 1:08pm UTC](https://forum.elixirforum.com/t/reference-a-static-variable-in-function-docs/19880 "2019-02-03T13:08:21Z")

</div>

Hi all, Earlier I found a resource that mentioned you can reference a static variable in function documents, but I’m unable to find the resource again to see how they did it. How do you do it? I’ve tried the following…

---

## [Implementing a counter, aka: how to keep state in a closure](https://forum.elixirforum.com/t/implementing-a-counter-aka-how-to-keep-state-in-a-closure/17056)

<div class="topic-metadata">

**Author:** [@Travis](https://forum.elixirforum.com/u/Travis)\
**Replies:** 4\
**Last updated:** [October 4, 2018, 6:08am UTC](https://forum.elixirforum.com/t/implementing-a-counter-aka-how-to-keep-state-in-a-closure/17056 "2018-10-04T06:08:24Z")

</div>

Completely new to Elixir, but have an issue I am trying to figure out: When interviewing candidates for Javascript roles I usually have them do a simple technical question: counter1 = getCounter(1); counter2 = getCoun…

---

## [How do I fix the unused variable's error which I used?](https://forum.elixirforum.com/t/how-do-i-fix-the-unused-variables-error-which-i-used/13916)

<div class="topic-metadata">

**Author:** [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Replies:** 1\
**Last updated:** [April 27, 2018, 2:25pm UTC](https://forum.elixirforum.com/t/how-do-i-fix-the-unused-variables-error-which-i-used/13916 "2018-04-27T14:25:08Z")

</div>

In my controller, I improved and prevent dirty code in my project, for example, I was trying to put my params in variable like this: Original codes : def create\_cms\_post(conn, %{ "title" =\> title, "status…
