Storing logic / functions

The creating module in the case of Code.eval_string/3 will always be :erl_eval. So while there is little danger of it going away there are could be some other interesting challenges lurking, in particular:

During evaluation of a function, no calls can be made to local functions. An undefined function error would be generated. However, the optional argument LocalFunctionHandler can be used to define a function that is called when there is a call to a local function.

and

The optional argument NonLocalFunctionHandler can be used to define a function that is called in the following cases:

  • A functional object (fun) is called.
  • A built-in function is called.
  • A function is called using the M:F syntax, where M and F are atoms or expressions.
  • An operator Op/A is called (this is handled as a call to function erlang:Op/A).

Now Code.eval_string/3 seems to handle this via the :functions option but essentially it seems to boil to the fact that any and all functions referenced within the string may have to be made available through the :functions option (or at least the modules need to be listed with the :requires option).

So the question becomes if you have already done a mockup of a scenario involving a reasonably complex “storable” function and got it to work - because it may not be as “easy” to generate these functions as you imagine - unless these functions don’t reference any other functions of note.

The issue is that you are planning to run potentially untrusted code - the necessary quarantine measures will likely erode most of the initially perceived “flexibility”. “specification data” can be designed to “sanitize-able” and “validate-able”, assessing the threat posed by unsigned/untrusted code is in an entirely different league.

Like isn’t need. And your initial complaint was that there were “so many variables to keep track” of - and from Elixir v1.2 they are capable of holding millions of keys efficiently. And while it is beneficial to delay some design decision as long as possible, it is also necessary and beneficial to choose the optimal constraints - without constraints there is only uncertainty because there is nothing you can rule out, safely ignore or disregard.

As I mentioned here OTP requires that you first learn about sequential Elixir and then concurrent Elixir - so it’s not surprising that entry level Elixir courses don’t even touch on OTP. Also video courses are only of limited value unless they contain a significant non-video exercise and “more substantial project” component.

For example Functional and Concurrent Programming in Erlang cites 5 hours per week for 3 weeks (each) which is enough to watch the lectures but to complete the exercises and projects it essentially turns into a part if not full-time job. And the first three weeks only cover pattern-matching, body and tail recursion, lists, and higher order functions - but completion of the exercises and project work helps tremendously with the formation of the “functional mindset”. And by the end of the second 3 weeks there is finally a single gen_server exercise (a third OTP oriented follow-up course is said to be in development).

1 Like