language-design

Creating a small programming language for beginners

我的未来我决定 提交于 2019-12-03 14:41:25
问题 I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language. I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with it. I have made the Hello world project in it, but how would I make a compiler in it? Are there any easy ways of creating a small programming language, I have heard of translating a language as in taking, e.g., Write() and making the computer

Are there any more elegant ways of handling lists in Java ? (Python VS Java)

不羁的心 提交于 2019-12-03 13:30:23
I do like the way I can treat lists in Python. It does any recursion solution to look easy and clean. For instance the typical problem of getting all the permutations of elements in a list, in Python looks like: def permutation_recursion(numbers,sol): if not numbers: print "this is a permutation", sol for i in range(len(numbers)): permutation_recursion(numbers[:i] + numbers[i+1:], sol + [numbers[i]]) def get_permutations(numbers): permutation_recursion(numbers,list()) if __name__ == "__main__": get_permutations([1,2,3]) I do like the way I can simple get new instances of modified lists by

Immutable Collections Actionscript 3

穿精又带淫゛_ 提交于 2019-12-03 12:30:04
问题 I've been trying lately to implement some clean coding practices in AS3. One of these has been to not give away references to Arrays from a containing object. The point being that I control addition and removal from one Class and all other users of the Array receive read only version. At the moment that read only version is a ArrayIterator class I wrote, which implements a typical Iterator interface (hasNext, getNext). It also extends Proxy so it can be used in for each loops just as a Array

OptionalInt vs Optional<Integer>

人走茶凉 提交于 2019-12-03 10:29:51
问题 When scrolling through the documentation for the java.util package, I was surpised to find that Optional<T> and OptionalInt have no relationship to each other. This seems very hard to belive, as it suggests that they are unrelated classes. Why don't they have a common interface, class, are sub-types, or something to reveal the relationship they have? (They're very similar classes when you look at their uses.) Also, why the need for an additional OptionalInt class? Why can't you just use

What compromises Scala made to run on JVM?

最后都变了- 提交于 2019-12-03 09:46:14
Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice? This article is a discussion with Martin Odersky (Scala's creator) and includes the compromises that were made in Scala for compatibility with Java. The article mentions: Static overloading of methods Having both traits and classes Inclusion of null pointers. VonC The two most important compromises I know about are: type erasure (" reflecting on Type "): It has to manage a Manifest to get around the Java compilation (independent of the JVM, for

What is the point of make_heap?

ε祈祈猫儿з 提交于 2019-12-03 09:18:58
Can someone please tell me the point of the STL heap function templates like std::make_heap ? Why would anyone ever use them? Is there a practical use? If you want to make a priority queue out from a list, well, you can use make_heap: Internally, a heap is a tree where each node links to values not greater than its own value. In heaps generated by make_heap, the specific position of an element in the tree rather than being determined by memory-consuming links is determined by its absolute position in the sequence, with *first being always the highest value in the heap. Heaps allow to add or

What is F# lacking for OO or imperative? [closed]

依然范特西╮ 提交于 2019-12-03 08:56:19
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Many times I hear that F# is not suited to particular tasks, such as UI. "Use the right tool" is a common phrase. Apart from missing

Why can't variable names have spaces in them? [duplicate]

流过昼夜 提交于 2019-12-03 08:23:21
This question already has answers here : Is there any language that allows spaces in its variable names [closed] (2 answers) Related: Why can't variable names start with numbers? Is there a technical reason why spaces aren't allowed in variable names or is it down to convention? For example, what's stopping us from doing something like this?: average score = sum of scores / number of scores The only issue that comes to mind is keywords, but one could simply restrict the use of them in a variable name, and the lexer would be able to distinguish between part of a variable and a keyword. There’s

Suggestions on syntax to express mathematical formula concisely

人走茶凉 提交于 2019-12-03 08:17:11
问题 I am developing functional domain specific embedded language within C++ to translate formulas into working code as concisely and accurately as possible. I posted a prototype in the comments, it is about two hundred lines long. Right now my language looks something like this (well, actually is going to look like): // implies two nested loops j=0:N, i=0,j (range(i) < j < N)[T(i,j) = (T(i,j) - T(j,i))/e(i+j)]; // implies summation over above expression sum(range(i) < j < N))[(T(i,j) - T(j,i))/e

Datatype promotion for dependently challenged

情到浓时终转凉″ 提交于 2019-12-03 08:11:07
问题 After reading through the ghc 7.4. pre-release notes and the Giving Haskell a Promotion paper, I'm still confused on what you actually do with promoted types. For example, the GHC manual gives the following examples on promoted datatypes: data Nat = Ze | Su Nat data List a = Nil | Cons a (List a) data Pair a b = Pair a b data Sum a b = L a | R b What kind of uses do these have as kinds? Can you give (code) examples? 回答1: There are at least two examples in the paper itself: "1. Introduction"