Elixir io_lib call to erlang - erlang

io_lib:fread("~d/~d/~d", "2013/03/03").
Above code works in erlang so ideally in elixir below code should work
:io_lib.fread("~d/~d/~d", "2013/03/03")
but it generates error " no function clause matching "
After inspecting found that elixir makes call to module like
:io_lib_fread.fread("~d/~d/~d", "2013/03/03", 0, [])

A double quote in erlang "char list" translates to single quotes in Elixir 'char list'.

Related

Bad function arity and warning: function hello_world/0 is unused

I just started learning Erlang so I coded this as new.erl:
-module(new).
-export([hello_world]/0).
hello_world()->io:fwrite("Hello\n").
So the function name is hello_world and it holds Hello as string.
But whenever I want to run this, I get this result:
new.erl:2: bad function arity
new.erl:3: Warning: function hello_world/0 is unused
error
So how to solve this problem, what's going wrong here ?
You wrote:
-export( [ hello_world ]/0 )
It should be:
-export( [ hello_world/0 ] ).
export requires a list, where each element in the list is the function name followed by a slash followed by the arity of the function. A list does not have an arity, which is what you wrote.
Note that when you are just writing test code, it is easier to use:
-compile(export_all).
which will export all functions defined in your module.

In Bazel, is it possible to use a function output as input to a load statement?

In Bazel, is it possible to use simple functions and variables as input to a load statement?
For example:
my_workspace = "a" + "b"
load(my_workspace, "foo")
load(my_workspace, "bar")
WARNING: Target pattern parsing failed.
ERROR: error loading package 'loadtest/simple': malformed load statements
The exact error message might have changed with version, I'd see:
syntax error at 'my_workspace': expected string literal
but no, you cannot use anything but string literal as per docs:
Use the load statement to import a symbol from an extension.
...
Arguments must be string literals (no variable)...

:erlang.list_to_atom("roster") error when accessing mnesia table

I am trying get mnesia table info from elixir shell.
I have tried to convert the string to atom.
String.to_atom("roster")
I have tried to pass string as list ["roster"]
command -
:ejabberd_admin.mnesia_table_info("roster")
error
ArgumentError
:erlang.list_to_atom("roster")
Erlang expects a charlist there, not a binary. Use single quotes:
:ejabberd_admin.mnesia_table_info('roster')
Also: Kernel.to_charlist/1, ~c/2.
Documentation on charlists on official site.
Example:
iex(1)> :erlang.list_to_atom("roster")
** (ArgumentError) argument error
:erlang.list_to_atom("roster")
iex(1)> :erlang.list_to_atom('roster')
:roster

Error using rascal Java15 grammar

I tried to parse some Java Code using the Java15 grammar of Rascal. However, it does not accept the declaration of local variable of parameterized types. In more details:
it does not recognize List<String> files = ...
it recognizes final List<String> files = ...
it recognizes List<String, String> files = ...
It seems to me that the problem is related to some ambiguity involving LocalVarDecStatements and expressions involving "<" and ">". However, I could not figure out how to fix the problem.
I'm not one to say "works for me", but it does :-) See:
rascal>import lang::java::\syntax::Java15;
ok
rascal>import ParseTree;
ok
rascal>parse(#LocalVarDec, "List\<String\> files = null")
LocalVarDec: (LocalVarDec) `List<String> files = null`
Could you provide the example or a simplified example which has the error in it?

ROBLOX Lua Error in script: '=' expected near '<eof>'

Hello I am writing a scipt on ROBLOX and I have encountered a problem.
function showVictoryMessage(playerName)
local message = Instance.new("Message")
message.Text = playerName .." has won!"
message.Parent = game.Workspace
wait (2)
message.Destroy()
end
Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script: '=' expected near '< eof >'
I have never seen this error before, and the ROBLOX wiki page on Lua errors doesn't mention it.
I would very much appreciate help in this, because I don't personally know anyone who has coded in Lua.
Looks like a syntax error. message.Destroy() should be message:Destroy() according to this Roblox wiki page http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy
Also see the section Explosions, Messages, and More at URL http://wiki.roblox.com/index.php?title=Basic_Scripting which provides similar syntax using the colon (:) operator.
See also Difference between . and : in Lua and explanation of "possible side-effects of calculations/access are calculated only once" with colon notation.
Instead of message.Destroy() it should be message:Destroy()
Remember that '.' are used directory-wise and ":' are used for inbuilt functions.
WOOOOOOOO! It was a syntax error. The correct command is message:Destroy. Cause why would object.Destroy work and message.Destroy not?

Resources