language-design

Adding a function in LLVM (haskell bindings) when the number of parameters is not known at compile time

别等时光非礼了梦想. 提交于 2019-12-12 07:37:16
问题 Background : I have written a toy Lisp interpreter that I am trying to add LLVM JIT functionality to. For the moment, have imposed the following limitations: Only integer values are allowed in functions Variables may only reference formal parameters Given : compile :: [Value] -- List of Formal Parameters -> [Value] -- Body of function -> CodeGenModule(Function a)` Question : How do I generate a function where the number of parameters equals the length of the Formal Parameters list? 回答1: I don

Exceptions as a control mechanism

烂漫一生 提交于 2019-12-11 23:57:31
问题 I was reading this post and laughed http://mcfunley.com/239/exceptions-are-not-a-control-mechanism In one of my apps i do not use File.Exist even tho i EXPECT files to exist a good deal of the time. I try to create a file without overwriting the older and if it fails i rename as Filename (Try Number).ext and loop until it opens. Should i used File.Exist in this case ? or should i continue to try opening a file, loop until i do then write pattern? 回答1: In my opinion exceptions should generally

Would “dereferencing” a foreign key in SQL theoretically work?

馋奶兔 提交于 2019-12-11 11:51:31
问题 Suppose we have 2 tables, a and b: CREATE TABLE a (id_a INT NOT NULL PRIMARY KEY, id_b INT NOT NULL) INDEX fk_id_b (id_b ASC), CONSTRAINT fk_id_b FOREIGN KEY (id_b) REFERENCES b (id_b); CREATE TABLE b (id_b INT NOT NULL PRIMARY KEY, b_data INT NOT NULL); So a has the following columns: id_a and id_b , where id_b is a foreign key to b s id_b . When I want to get the associated b_data from a, I have to do a join: SELECT id_a, b_data FROM a JOIN b ON a.id_b=b.id_b; It works fine, but it's long,

An XML language for describing file attributes of a directory tree?

邮差的信 提交于 2019-12-11 02:33:06
问题 I have an application in mind which will record directory listings of a file system in text form. That is, it should say something like: File name is: abc.txt Last modification date is: 2009-12-31T01:23 Read-only attribute is: True Hidden attribute is: False The listings will persist for years in a long-term archive, so the language should be self-evident to an information archaeologist of the future. The language should be able to describe the most commonly-used file attributes of common PC

What's the benefit of the trailing apostrophe in character literals

风格不统一 提交于 2019-12-11 00:59:02
问题 I am writing my own programming language and am reconsidering many aspects of my syntax right now. Something that bothers me in many most languages is the trailing apostrophe in character literals. Example With trailing slash: 'n' Without trailing slash: 'n Why do new languages (like rust f.e.) keep using a trailing apostrophe ? Seeing such languages fixing issues we had with old languages (ok, the trailing apostophe is not really an issue) leaves me thinking that there must be a benefit to

Recognize multiple line comments within a single line with ANTLR4

北城余情 提交于 2019-12-10 21:52:04
问题 I want to parse PostScript code with ANTLR4. I finished with the grammar, but one particular language extension (which was introduced by someone else) makes trouble being reconized. A short example: 1: % This is a line comment 2: % The next line just pushes the value 10 onto the stack 3: 10 4: 5: %?description This is the special line-comment in question 6: /procedure { 7: /var1 30 def %This just creates a variable 8: /var2 10 def %?description A description associated with var2 %?default 20

Class instance as static attribute

a 夏天 提交于 2019-12-10 21:08:34
问题 Python 3 doesn't allow you to reference a class inside its body (except in methods): class A: static_attribute = A() def __init__(self): ... This raises a NameError in the second line because 'A' is not defined . Alternatives I have quickly found one workaround: class A: @property @classmethod def static_property(cls): return A() def __init__(self): ... Although this isn't exactly the same since it returns a different instance every time (you could prevent this by saving the instance to a

PHP: How are comments skipped?

匆匆过客 提交于 2019-12-10 19:11:00
问题 Well if I comment something it's skipped in all languages, but how are they skipped and what is readed? Example: // This is commented out Now does PHP reads the whole comment to go to next lines or just reads the // ? 回答1: Your question doesn't make sense. Having read the '//', it then has to keep reading to the newline to find it. There's no choice about this. There is no other way to find the newline. Conceptually, compiling has several phases that are logically prior to parsing: Scanning.

C++ exceptions and signal handlers

﹥>﹥吖頭↗ 提交于 2019-12-10 16:42:37
问题 I am reading The Design and Evolution of C++ , by Bjarne Stroustrup. Regarding exeception handling and asynchronous signals it is mentioned as below: Can exceptions be used to handle things like signals? Almost certainly not in most C environments. The trouble is that C uses functions like malloc that are not re-entrant. If an interrupt occurs in the middle of malloc and causes an exception, there is no way to prevent the exception handler from executing malloc again. A C++ implementation

C# language design pillars

吃可爱长大的小学妹 提交于 2019-12-10 16:17:24
问题 In the article (http://www.artima.com/intv/nonvirtualP.html) Anders Hejlsberg mentioned that versioning is one of the pillars of C# language design. Does anybody know what are other pillars? 回答1: I refer you to page one of the C# specification, which describes the important factors that went into the design of the language. A few quotes that indicate what some of the important factors were, and continue to be: modern, object-oriented, and type-safe -- immediately familiar to C, C++, and Java