erlang

Erlang and JavaScript MD5 Digest match

£可爱£侵袭症+ 提交于 2019-12-21 15:39:23
问题 Testing the Javascript Implementation of MD5 here: http://www.webtoolkit.info/javascript-md5.html gives the following output: MD5("muzaaya") = "00e081abefbbbf72b2d5258196a9b6d0" Going to my erlang shell, and calculating the MD5 of the same value i get this: Eshell V5.8.4 (abort with ^G) 1> erlang:md5("muzaaya"). <<0,224,129,171,239,187,191,114,178,213,37,129,150,169, 182,208>> 2> How can i compare the two? If the MD5 result from the JavaScript front end app comes to my Erlang backend, i would

函数式编程与面向对象编程[关闭]

谁说胖子不能爱 提交于 2019-12-21 12:04:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 到目前为止,我已经主要接触过OO编程,并期待学习一门函数式语言。 我的问题是: 什么时候选择面向对象的函数式编程? 什么是典型的问题定义,其中函数式编程是更好的选择? #1楼 您不一定要在两种范例之间进行选择。 您可以使用许多功能概念编写具有OO架构的软件。 FP和OOP本质上是正交的 。 以C#为例。 你可以说它主要是OOP,但有许多FP概念和结构。 如果考虑 Linq ,允许Linq存在的最重要的构造本质上是功能性的: lambda表达式 。 另一个例子,F#。 你可以说它主要是FP,但有许多OOP概念和结构可用。 您可以定义类,抽象类,接口,处理继承。 您甚至可以在使代码更清晰或显着提高性能时使用可变性。 许多现代语言都是多范式的。 推荐读物 因为我在同一条船上(OOP背景,学习FP),我建议你读一些我真的很感激: Jeremy Miller 为日常.NET开发提供的功能编程 。 一篇很棒的文章(虽然格式很差),展示了C#上FP的许多技术和实际的实际例子。 真实世界的功能编程 ,由Tomas Petricek撰写。 一本伟大的书,主要涉及FP概念,试图解释它们是什么,什么时候应该使用它们。 F#和C#都有很多例子。 此外, Petricek的博客 是一个很好的信息来源。 #2楼 如果您处于高度并发的环境中

What is the difference between a Binary and a Bitstring in Erlang?

我是研究僧i 提交于 2019-12-21 11:26:08
问题 In the Erlang shell, I can do the following: A = 300. 300 <<A:32>>. <<0, 0, 1, 44>> But when I try the following: B = term_to_binary({300}). <<131,104,1,98,0,0,1,44>> <<B:32>> ** exception error: bad argument <<B:64>> ** exception error: bad argument In the first case, I'm taking an integer and using the bitstring syntax to put it into a 32-bit field. That works as expected. In the second case, I'm using the term_to_binary BIF to turn the tuple into a binary, from which I attempt to unpack

How do I XML-encode a string in Erlang?

喜欢而已 提交于 2019-12-21 09:26:23
问题 I have a erlang string which may contain characters like & " < and so on: 1> Unenc = "string & \"stuff\" <". ok Is there a Erlang function somewhere that parses the string and encodes all the needed HTML/XML entities, such as: 2> Enc = xmlencode(Unenc). "string & "stuff" <". ? My use case is for relatively short strings, which come from user input. The output strings of the xmlencode function will be the content of XML attributes: <company name="Acme & C." currency="€" /> The final XML will

performance penalty of message passing as opposed to shared data

∥☆過路亽.° 提交于 2019-12-21 09:22:33
问题 There is a lot of buzz these days about not using locks and using Message passing approaches like Erlang. Or about using immutable datastructures like in Functional programming vs. C++/Java. But what I am concerned with is the following: AFAIK, Erlang does not guarantee Message delivery. Messages might be lost. Won't the algorithm and code bloat and be complicated again if you have to worry about loss of messages? Whatever distributed algorithm you use must not depend on guaranteed delivery

In Erlang how can I import all functions from a module?

假如想象 提交于 2019-12-21 08:59:26
问题 I can't figure out how to import all the functions of a module without having to specify the individual functions. 回答1: As Christian says, "It is not possible to import all functions from a module." The compiler has no import_all directive and I think this is done deliberately to discourage excessive function importing. Importing functions instead of fully qualifying them M:F(...) is usually bad style. There is a semantic difference between calling a module-local function and a function in

extraction of elements of tuples

爱⌒轻易说出口 提交于 2019-12-21 07:06:23
问题 Given one list with one tuple: [{4,1,144}] How to extract the first element of the tuple: element(1,lists:nth(1,L)) Do you have a simpler solution? 回答1: Try this: 1> A = [{3,1,1444}]. [{3,1,1444}] 2> [{X, _, _}] = A. [{3,1,1444}] 3> X. 3 4> 回答2: Given that you get exactly what you state, a list with one tuple, even easier would be (using element/2) element(1, hd(L)). A pattern matching variant like shk suggested is probably even nicer, depending on the context. 回答3: you could also consider

Concurrency: Processes vs Threads

若如初见. 提交于 2019-12-21 06:59:45
问题 What are the main advantages of using a model for concurrency based on processes over one based on threads and in what contexts is the latter appropriate? 回答1: Fault-tolerance and scalability are the main advantages of using Processes vs. Threads. A system that relies on shared memory or some other kind of technology that is only available when using threads, will be useless when you want to run the system on multiple machines. Sooner or later you will need to communicate between different

An efficient algorithm to calculate the integer square root (isqrt) of arbitrarily large integers

﹥>﹥吖頭↗ 提交于 2019-12-21 05:05:10
问题 Notice For a solution in Erlang or C / C++ , go to Trial 4 below. Wikipedia Articles Integer square root The definition of "integer square root" could be found here Methods of computing square roots An algorithm that does "bit magic" could be found here [ Trial 1 : Using Library Function ] Code isqrt(N) when erlang:is_integer(N), N >= 0 -> erlang:trunc(math:sqrt(N)). Problem This implementation uses the sqrt() function from the C library, so it does not work with arbitrarily large integers

How to get the memory location of a variable in Elixir?

Deadly 提交于 2019-12-21 04:55:13
问题 A fact that we know about Elixir is that data structures that lives in memory are immutable, and variables are just pointers to those data structures. Is there a way for us to get the memory address of a variable is pointing to, instead of the content in that memory location (i.e. the dereferenced value of the variable)? For me, the purpose of doing so is that we can learn about how Elixir/Erlang manages memory when dealing with duplicated values, like two same character lists, or especially