Tag Info

New answers tagged

1

I think you're thinking of Rosetta Code


0

I strongly suggest reading Queinnec's book Lisp In Small Pieces, it has several chapters to answer your question, taking into account your practicality request (without which some bare lambda-calculus would be enough); it also goes from simplistic mini-scheme interpreter (as an implementation of eval) to a complete Lisp-like compiler (to bytecode and to C). ...


0

Languages that support implicit conversions/casts, or weak typing as it is sometimes referred to, will make assumptions for you that don't always match up with the behavior you intended or expected. The designers of the language may have had the same thought process as you did for a certain type of conversion or series of conversions, and in that case ...


-1

If you target LLVM, you still need to preprocess and actually compile the input, but output can then be in any of the outputs LLVM allows, be it assembly or JavaScript.


0

If you translate whatever you have to C, then you have a working system wherever a C compiler is available. Which is basically everywhere. You don't have to worry about different processors, different operating systems, and all the rest. You may instead compile to C++, which today is almost as common as C, and gives you the advantage that you can hide work ...


2

I did some professional work three years ago that used reflection to understand a .NET interface and provide some CIL glue to mangle it onto a base class. It was an eye opener to the level of additional work required. Most software development, you focus on the success routes and if something unexpected happen you catch an exception. I found that the ...


3

You should consider compiling to C (see this and that answers), or to some other languages (Java, Common Lisp, Ocaml, or even a mix of Javascript & C - like HOP does...) You could also compile to the textual representation of LLVM bytecode, or use the LLVM library as your backend, or (if having GCC 5 or better) use the libgccjit (to target GCC internal ...


11

I am going to focus on your core question, since other stuff has been answered elsewhere. Should you target a higher level language or assembly? Getting software done is hard. While making a new language can be pretty easy, you need to stick to simple stuff and avoid the stuff that is a pain to implement. Making your first language has the problem that ...


1

Because of the way the expression is parsed and evaluated, a sum function will get the results of the EnumFromTo, and therefore under normal conditions there is no way to get at its arguments. To receive the unevaluated arguments, you would need to use a macro. I don't know anything about Template Haskell, but supposedly it provides this ability. In ...


-2

Check this (Clojure code, sorry I don't know Haskell): (declare m-enum-upto) (defn enum-upto [n] (cond (= n 0) 0 (= n 1) 1 :else (+ n (m-enum-upto (dec n))))) (def m-enum-upto (memoize enum-upto)) ; at the first run (enum-upto 5) ; 0.497711 msec ;again (enum-upto 5); 0.1130686 msec ;and now (enum-upto 3); 0.09372 msec (enum-upto 30); ...


32

For what it's worth, len(str(100)), len(chr(100)) and len(hex(100)) are all different. str is not the only way to make it work, since there's more than one different conversion in Python from an integer to a string. One of them of course is the most common, but it doesn't necessarily go without saying that's the one you meant. An implicit conversion ...


2

Explicit casts are important for they're making your intent clear. First of all using explicit casts tells a story to someone who is reading your code. They reveal that you intentionally did what you did. Moreover the same applies to the compiler. The following is illegal in C# for example double d = 3.1415926; // code elided int i = d; The cast will make ...


3

Implicit conversions can be a real pain to work with. In PowerShell: $a = $(dir *.xml) # typeof a is a list, because there are two XML files in the folder. $a = $(dir *.xml) # typeof a is a string, because there is one XML file in the folder. Suddenly there is twice as much testing needed and twice as many bugs as there would be without implicit ...


10

ColdFusion did most of this. It defines a set of rules to handle your implicit conversions, has a single variable type, and there you go. The result is total anarchy, where adding "4a" to 6 is 6.16667. Why? Well, because the first of the two variables is a number, so the result will be numeric. "4a" is parsed as a date, and seen as "4 AM". 4 AM is ...


5

Imagine for a moment the context of your statement. You say this is the "only way" it could work, but are you really sure it will work like that? What about this: def approx_log_10(s): return len(s) print approx_log_10(3.5) # "3" is probably not what I'm expecting here... As others have mentioned, in your very specific example, it seems simple for ...


7

You're saying that implicit conversions could be a good idea for operations that are unambiguous, like int a = 100; len(a), where you obviously mean to convert the int to a string before calling. But you're forgetting that these calls may be syntactically unambiguous, but they may represent a typo made by the programmer who meant to pass a1, which is a ...


14

Implicit conversions are quite possible to do. The situation where you get in trouble is when you don't know which way something should work. An example of this can be seen in Javascript where the + operator works in different ways at different times. >>> 4 + 3 7 >>> "4" + 3 43 >>> 4 + "3" 43 If one of the arguments is a ...


26

As I understand it, implicit conversions can cause errors. You're missing a word: implicit conversions can cause runtime errors. For a simple case like you show, it's pretty clear what you meant. But languages can't work on cases. They need to work with rules. For many other situations, it's not clear if the programmer made an error (using the wrong ...


3

Assembler languages are processor (or CPU) specific. Each processor has its own assembler language (which maps to a different machine language). So SPARC processors use SPARC assembler, x86-64 processors use x86-64 assembler, etc. For a few processors, including x86-64 used in most laptops & desktops in 2015, you might have two different syntaxes so two ...


-1

Here is a program that computes the faculty of 6: S(K(S(S(SI(KK))(K(S(S(KS)(S(KK)(S(KS)(S(K(SI))K))))(KK)(KI)(S(S(KS)(S(KK) (S(KS)(S(K(SI))K))))(KK)KK))))))(S(K(S(S(K(SI))(SII)(S(K(SI))(SII)) (S(K(S(S(KS)(S(KK)(S(SI(KK))(K(S(S(KS)(S(KK)(S(KS)(S(K(SI))K))))(KK)KK))))))) (S(K(S(S(KS)(S(K(SI(KK)))(SI(K(KI)))))))(S(K(S(K(S(S(K(SI))(SII)(S(K(SI)) ...


2

The only way for a conversion from language X to some intermediate language IL and back to be lossless is for IL to be a superset of X. If you want to have multiple languages as X, then IL has to be a superset of all of them. Therefore, I would suggest that IL has the following structure: delimiter: ---------SOMERANDOMSTRING---------- ...


4

Some intermediate languages have been successfully used as target for a lot of various languages, e.g. LLVM (or Ramsey & Jones' C--, which might be a dead project in 2015) Notice that an intermediate language does not carry all the information provided in the source language (e.g. you are losing information when compiling from C to LLVM). However, I am ...


7

Once a language has been compiled down to assembler or even to say CIL or JVM, concepts such as if statements are lost as they are turned into branches. Not particularly in practice. If you look at a tool like Reflector, it will happily turn CIL back into pretty accurate C# code, ifs and all. So, having said all that, is there a language who's goal ...


3

I can't think of any downsides to this so long as your parser non parser sides are truly separate. If you end up implementing the same things twice, in two different languages, that is problematic due to bugs when they likely don't always behave the same ways, as well as duplicated effort. If that isn't going to happen, it seems like a fine idea and makes ...


5

What is it about Haskell that has led to it's rise in popularity among experts in the FP world? There's a few of different things I've seen: It's novel. As much as FP enthusiasts poo-poo all of the fads in imperative and OO programming, they're still human. Lisp has been around since the 60's. ML since the 70's. A lot of people have spent a lot of ...


1

Do I lose any optimization opportunity if I choose to compile my language down to Java instead of the JVM bytecode? Opportunity? Sure. Your language knows about its semantics and its limitations. If you have certain features that could be optimized, then you can make those optimizations and output the better bytecode. If you go to Java, Java needs to ...


0

I was trying to think of why both of these languages went this route instead of inverting it and having == be logical equality and using .ReferenceEquals() for reference equality. Because the latter approach would be confusing. Consider: if (null.ReferenceEquals(null)) System.out.println("ok"); Should this code print "ok", or should it throw a ...


5

The overarching theme of your question seems to be succinctly summed up in the last paragraph: "What are the benefits to using these preproc'd languages, especially given the fact that they're not browser supported?" What's fantastic about preprocessors is that they don't need to be supported by the browsers. They are taking the non-native-web input and ...


6

I see plenty of reason why you should embrace pre-processed languages, and I'll try to demonstrate the benefits of those tools. 1. Paradigm shift In my opinion, the greatest feature of any pre-processed language is the ability you to develop and solve problems in a different mindset compared to the standard HTML/CSS/JS way. In short, pre-processing can ...


-2

All answers fall short of the real problem: C++ compiling introduces "name mangling", so binaries are incompatible with "simple" function calls. All ABI stuff is little more than an attempt to standardize it. In general it's not guaranteed you can cross-link functions compiled with different compilers, even if you stick to plain C++. Formerly it was sure ...


0

Fundamentally it comes down to the ABI standardisation. While neither C nor C++ has a standardised ABI that other languages can use to interface between binaries written, C has become a de-facto standard, everyone knows it and everyone else can use the same, simple, rules that the language has with respect to types and function calls. C++ could have a ...


2

There are two major axes when interfacing with another language: the concepts that the interface can carry over: just values? references? generics? how the interface is implemented in "binaries" (called ABI) C has an advantage over C++ on those two fronts: C only has mostly simple concepts, which appear in most every other language1 The ABI of C ...


20

C is one of the oldest languages still around. Its ABI is simple, and virtually every operating system still in use today has been written in it. While some of those OS's may have added stuff e.g. in C#/.NET or whatever on-top, down below they're very much steeped in C. That means that, in order to use the functionality provided by the OS, virtually every ...


6

Leaving out the details other answers already provide: The reason so many languages provides a C binding is that all *nix and Windows operating systems expose most of their OS API via a C interface. So the language implementation already needs to interface with C to be able to run on the major Oses. Therefore, it is straightforward to also offer directly ...


29

If you're trying to communicate with a speaker of another language, pidgin is easier than Shakespearean English. C's concepts - function calls, pointers, NULL-terminated strings - are very straightforward, so other languages can easily implement them well enough to call C functions. For historical reasons, many other languages are implemented in C, which ...


62

C has a much, much simpler interface, and its rules for converting a source code interface into a binary interface are straightforward enough that generating external interfaces to bind to is done in a well-established manner. C++, on the other hand, has an incredibly complicated interface, and the rules for ABI binding are not standardized at all, neither ...


5

There is no reason. If the semantics you're trying to express are fundamentally C-compatible and not something like templates, there is no reason you can bind easier if the implementation is written in C. In fact, it's pretty much by definition that a C interface can be filled out by any implementation that can meet the binary contract- including an ...



Top 50 recent answers are included