2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

llama-2 で elixir を学ぶ (その2) 整数の加算

Last updated at Posted at 2024-03-21

こちらと同じことを、llama-2 で行いました。
ChatGPT で elixir を学ぶ (その2) 整数の加算

Python のプログラム

sum.py
#! /usr/bin/python
#
import sys
#
sys.stderr.write("*** 開始 ***\n")
aa = int(sys.argv[1])
bb = int(sys.argv[2])
print("aa = %d\tbb = %d" % (aa,bb))
sum = aa + bb
print("sum = %d" % sum)
sys.stderr.write("*** 終了 ***\n")

llama-2 が作成したプログラム

ex02.exs
#! /usr/bin/elixir

def main(args) do
  # Print a message to stderr
  System.error("*** 開始 ***\n")

  # Parse command line arguments
  aa = Integer.parse(args[1])
  bb = Integer.parse(args[2])

  # Print some information to stderr
  System.error("aa = #{aa}\tbb = #{bb}")

  # Calculate the sum of the two integers
  sum = aa + bb

  # Print the result to stderr
  System.error("sum = #{sum}")

  # Print a message to stderr indicating that the program has finished
  System.error("*** 終了 ***\n")
end

main([String.to_list(System.get_property("user.home"))])

実行結果

$ ./ex02.exs  10 20
** (ArgumentError) cannot invoke def/2 outside module
    (elixir 1.14.0) lib/kernel.ex:6373: Kernel.assert_module_scope/3
    (elixir 1.14.0) lib/kernel.ex:5070: Kernel.define/4
    (elixir 1.14.0) expanding macro: Kernel.def/2
    ex02.exs:3: (file)

llama-2 に次の質問をしました。

Is System.error() a standard function for Elixir?

回答

No, `System.error()` is not a standard function in Elixir. 
It is a function provided by the Erlang VM's `sys` module, 
which is not available in Elixir.

image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?