Tag Info

New answers tagged

6

That is a list comprehension. Spread out a bit, it would look something like: h_data = [] for e in cube_edges: if cube_signs[e[0]] != cube_signs[e[1]]: h_data.append(estimate_hermite(f, df, o+cube_verts[e[0]], o+cube_verts[e[1]]))


-1

What you present in your question is a context-free (CF) grammar, omitting details about terminal (which symbols are in the generated text) and non-terminals (which symbols are used only to be rewritten (expanded), and the initial symbol (which non-terminal you start with). BNF (Backus-Naur Form) is a specific syntax (syntactic style) for presenting CF ...


2

Apart from some formatting issues (-> doesn't exist in formal BNF), your rule is correct. Written in proper BNF syntax and using quotes around literals, it would be C ::= C '&&' E | E The left-recursion indeed creates a parse tree for a left-associative operator.


1

You have some excellent answers above but given that, in a comment, you answered the question "Why do you want to create a programming language of your own in the first place? " with "It would be for learning purpose mainly," I'm going to answer from a different angle. It makes sense to write a converter that takes the source code and converts it to C or ...


15

Tranlating to C code is a very well established habit. The original C with classes (and the early C++ implementations, then called Cfront) did that successfully. Several implementations of Lisp or Scheme are doing that, e.g. Chicken Scheme, Scheme48, Bigloo. Some people translated Prolog to C. And so did some versions of Mozart (and there have been attempts ...


3

It makes sense when the time to generate full machine code outweighs the inconvenience of having an intermediate step of compiling your "IL" into machine code using a C compiler. Typically domain-specific languages are written in this way, a very high level system is used to define or describe a process that is then compiled into an executable or dll. The ...


-5

It depends on what Operating System you are using if you are using Windows there is a Microsoft IL (Intermediate Language) Which converts your code into intermediate language so that it takes no time to get compiled into machine code. Or If you are using Linux there is a separate compiler for that Coming back to your question is when you when designing your ...


1

For some languages functions are not values. In such a language to say that val f = << i : int ... >> ; is a function definition, whereas val a = 1 ; declares a constant, is confusing because you are using one syntax to mean two things. Other languages, such as ML, Haskell, and Scheme treat functions as 1st class values, but provide the ...


2

Well, the reason might be, that those languages are not functional enough, so to say. In other words, you rather seldomly define functions. Thus, the use of an extra key word is acceptable. In languages of the ML or Miranda heritage, OTOH, you define functions most of the time. Look at some Haskell code, for instance. It's literally mostly a sequence of ...


10

You might be interested to learn that, way back in prehistoric times, a language called ALGOL 68 used a syntax close to what you propose. Recognising that function identifiers are bound to values just like other identifiers are, you could in that language declare a function (constant) using the syntax function-type name = (parameter-list) result-type : ...


8

You mentioned Java and Scala as examples. However, you overlooked an important fact: those aren't functions, those are methods. Methods and functions are fundamentally different. Functions are objects, methods belong to objects. In Scala, which has both functions and methods, there are the following differences between methods and functions: methods can ...


0

Functions are declared differently from literals, objects, etc. in most languages because they are used differently, debugged differently, and pose different potential sources of error. If a dynamic object reference or a mutable object is passed to a function, the function can change the value of the object as it runs. This kind of side effect can make it ...


3

Turning the question around, if one isn't interested in trying to edit source code on a machine which is extremely RAM-constrained, or minimize the time to read it off a floppy disk, what's wrong with using keywords? Certainly it's nicer to read x=y+z than store the value of y plus z into x, but that doesn't mean that punctuation characters are inherently ...


1

Personally, I see no fatal flaw in your idea; you may find that it's trickier than you expected to express certain things using your new syntax, and/or you may find that you need to revise it (adding various special cases and other features, etc), but I doubt you'll find yourself needing to abandon the idea entirely. The syntax you've proposed looks more or ...


44

I think the reason is that most popular languages either come from or were influenced by the C family of languages as opposed to functional languages and their root, the lambda calculus. And in these languages, functions are not just another value: In C++, C# and Java, you can overload functions: you can have two functions with the same name, but ...


0

There is a very simple reason to have such a distinction in most languages: there is a need to distinguish evaluation and declaration. Your example is good: why not like variables? Well, variables expressions are immediately evaluated. Haskell has a special model where there is no distinction between evaluation and declaration, which is why there is no need ...


3

The reasons that I can think of are: It is easier for the compiler to know what we declaring. It's important for us to know (in a trivial way) whether this is a function or a variable. Functions are usually black boxes and we don't care about their internal implementation. I dislike type inference on return types in Scala, because I believe that it's ...


0

This might be useful on dynamic languages where the type is not that important, but it's not that readable in static typed languages where always you want to know the type of your variable. Also, in object-oriented languages it's pretty important to know the type of your variable, in order to know what operations it supports. In your case, a function with 4 ...


56

It's because it's important for humans to recognize that functions are not just "another named entity". Sometimes it makes sense to manipulate them as such, but they are still able to be recognized at a glance. It doesn't really matter what the computer thinks about the syntax, as an incomprehensible blob of characters is fine for a machine to interpret, ...



Top 50 recent answers are included