Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError iex: syntax error before: abci_server #5

Closed
ltfschoen opened this issue Jan 27, 2018 · 2 comments
Closed

SyntaxError iex: syntax error before: abci_server #5

ltfschoen opened this issue Jan 27, 2018 · 2 comments

Comments

@ltfschoen
Copy link

ltfschoen commented Jan 27, 2018

When I load the abci_server Docs in my Web Browser with:

cd deps/abci_server/ && make docs && open doc/index.html && cd ../../

The Documentation tells me I can:

To start a server on port 46658 that delegates calls to the foo module, write:

{ok, _} = abci_server:start_listener(foo, 46658).

So to try it out I add abci_server to mix.exs

defp deps do
  [
    {:abci_server, git: "https://github.com/KrzysiekJ/abci_server.git", tag: "v0.4.0"},
    # Ranch is a dependency of ABCI Server (Erlang), which is using the older 
    # version of Ranch 1.3.2, which does not support the latest GNU Make 4
    # Temporarily install Ranch 1.4.0 here until Pull Request https://github.com/KrzysiekJ/abci_server/pull/3
    # is approved and newer version of abci_server is released that uses the latest Ranch version 
    {:ranch, git: "https://github.com/ninenines/ranch.git", tag: "1.4.0"}
  ]
end

Then I install the Mix dependencies

mix deps.get

Then I run IEx within context my Elixir App (loading app and dependencies into IEx runtime)

iex -S mix

Then I create a fake module just to test it out try and Start the abci_server as instructed as follows, but it gives me error (SyntaxError) iex:2: keyword argument must be followed by space after: abci_server: when I try to run the server

iex(1)> defmodule Foo do             
...(1)>     def bar() do               
...(1)>       IO.puts("Hello, World!") 
...(1)>     end
...(1)>   end
{:module, Foo,
 <<70, 79, 82, 49, 0, 0, 4, 80, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 136,
   0, 0, 0, 15, 10, 69, 108, 105, 120, 105, 114, 46, 70, 111, 111, 8, 95, 95,
   105, 110, 102, 111, 95, 95, 9, 102, 117, ...>>, {:bar, 0}}

iex(2)> {ok, _} = abci_server:start_listener(Foo, 46658)  
** (SyntaxError) iex:2: keyword argument must be followed by space after: abci_server:

I'm still new to Elixir/Erlang, but I found this post elixir-lang/elixir-lang.github.com#980 and it indicates that I should add a space after the colon :, but then it just gives me a generic syntax error:

iex(3)> {ok, _} = abci_server: start_listener(BlockchainTendermint, 46658).
** (SyntaxError) iex:3: syntax error before: abci_server

So I did more research and I found this link which says I can use Erlang packages that are installed as dependencies from an Elixir project’s Mix file https://elixirschool.com/en/lessons/advanced/erlang/#erlang-packages.
So according to their guide, if I include an Erlang Library in mix.exs as {:abci_server, git: "https://github.com/KrzysiekJ/abci_server.git", tag: "v0.4.0"},, then I should be able to check it has loaded and use it’s associated functions when I run IEx with iex(3)> :abci_server.__info__(:functions), but doing so just returns ** (UndefinedFunctionError) function :abci_server.__info__/1 is undefined or private

@ltfschoen ltfschoen changed the title SyntaxError iex: keyword argument must be followed by space after: abci_server: SyntaxError iex: syntax error before: abci_server Jan 27, 2018
@ltfschoen
Copy link
Author

I finally overcame the problem after posting the question in the Elixir Slack group https://elixir-lang.slack.com/archives/C03EPRA3B/p1517016786000068.

First with some help I was able to show information about the :abci_server to confirm it had been successfully imported. I was told that __info__/1 is an Elixir thing the compiler adds, and that I should use module_info/1 which is the Erlang equivalent - https://elixir-lang.slack.com/archives/C03EPRA3B/p1517018221000028

iex> :abci_server.module_info  
[
  module: :abci_server,
  exports: [
    start_link: 4,
    start_listener: 2,
    child_spec: 2,
    stop_listener: 1,
    init: 1,
    handle_call: 3,
    handle_cast: 2,
    handle_info: 2,
    terminate: 2,
    code_change: 3,
    module_info: 0,
    module_info: 1
  ],
  attributes: [
    vsn: [86973587470476204871336807197797490126],
    behaviour: [:gen_server],
    behaviour: [:ranch_protocol]
  ],
  compile: [
    options: [
      :debug_info,
      {:i,
      '/Users/Ls/code/blockchain/tendermint-elixir/blockchain_tendermint/deps/abci_server/include'},
      :warn_obsolete_guard,
      :warn_shadow_vars,
      :warn_export_vars
    ],
    version: '7.1.4',
    source: '/Users/Ls/code/blockchain/tendermint-elixir/blockchain_tendermint/deps/abci_server/src/abci_server.erl'
  ],
  native: false,
  md5: <<65, 110, 128, 239, 19, 146, 215, 5, 182, 173, 33, 116, 159, 63, 157,
    206>>
]

I then created a fake Foo function:

iex>  defmodule Foo do             
        def bar() do               
          IO.puts("Hello, World!") 
        end
      end

And then lastly I called the start_listener function, using syntax recommended in the Slack channel:

iex> {ok, _} = :abci_server.start_listener(Foo, 46658)
{:ok, #PID<0.181.0>}
iex> ok = :abci_server.stop_listener(Foo)             
:ok

I've updated this Pull Request #3 with proposed updates to the Readme, since the Generated Docs may not be clear enough for beginners

@KrzysiekJ
Copy link
Owner

The line

{ok, _} = abci_server:start_listener(foo, 46658).

is intended to be used in Erlang shell, hence it uses the Erlang syntax. As noted, syntax for Elixir shell will be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants