In the language nim, one can do the following thing:
let num = 5.add(3)
which would be the same as
let num = add(5,3)
So, basically you take the expression before the dot as the first argument to the function.
I'm sure other languages have this feature, but none directly came to mind.
What I want to know is what name this syntax has
In D lang this syntax is called Uniform Function Call Syntax (UFCS).
The manual says it's the method call syntax. It also mentions dot operators.
TL;DR - Unified [Function] Call Syntax, or whatever you like, because there's no stable widely accepted term for that in software engineering.
The concern is based on the info about programming languages that somehow implement this feature:
C++: The most generic name for the feature is possibly Unified Call Syntax as defined by Herb Sutter at open-std.org paper in cooperation with Bjarne Stroustrup as a possible new feature for further C++ standards.
D2: In D language, and also in and RFC for the Rust Language it is called UFCS (Unified Function Call Syntax).
MATLAB: In MATLAB they don't use any specific naming for the fact methods can be called either via function notation or via '.' (dot) syntax.
Related
Not long ago I acquired the second edition of Software Abstractions, and when I needed to refresh my memory on how to spell the name of the elems function I thought "Oh, good, I can check the new edition instead of trying to read my illegible handwritten notes in the end-papers of the first edition."
But I can't find "seq" or "elems" or the names of any of the other helper functions in the index, nor do I see any mention of the seq keyword in the language reference in Appendix B.
One or more of the following seems likely to be the case; which?
I am missing something. (What? where?)
The seq keyword is not covered in Appendix B because it's not strictly speaking a keyword in the way that set and the other unary operators are. (Please expound!)
The support for sequences was added to Alloy 4 after the second edition went to press, and so the book needs to be augmented by reference to the discussion of new features in Alloy 4 in the Quick Guide and the Alloy 4 grammar on the Web site. (Ah, OK. Pages are slow, bits are fast.)
Other ...
I guess, to try to put a generally useful question here, that I'm asking: what exactly is the relation between the language implemented by the Alloy Analyzer 4.2 (or any 4.*) and the language defined in Software abstractions second edition?
The current implementation corresponds to this online documentation.
Sequences are really not part of the language; x: seq A can be seen just as a syntactic sugar for x: Int -> A, and all the utility functions (e.g., first, last, elems) are library-defined (in util/sequence). The actual implementation is a little more complicated (just so that we can let the user write something like x.elems and make the type checker happy at the same time), but conceptually that's what's going on.
I like programming language design/implementation and I'd like to contribute to one of the less mature ones. I'm looking for a scripting language that is:
Embeddable
Dynamically, strongly typed
Small & Lightweight (more elaborated later)
Implemented in C++
With lightweight I mean something like Lua, very small standard library that can be easily extended.
And some (random) design principles that I like:
The language should have a few very powerful built-in types, like python (int, float, list/array, map/dictionary, set and tuple).
A function is an object, like in Lua (this makes lambda functions trivial)
Arguments are passed as tuples that automatically get extracted.
And last and probably also least, I like C-style syntax.
If you think about yelling "subjective", "there is no best language" and "not a question", you misread a question. I'm merely asking for a list of scripting languages that match the description above.
Cython
Shedskin
Psyco
These are all scripting languages that are either variants or restricted subsets of the original; python language, that compile to C, C++, or machine code. I believe these should satisfy your req. spec.
Shedskin and psyco also currently have calls for contributions on their main page.
HTH
Is there a programming language that uses inflections (suffixing a word to add a certain meaning) instead of operators to express instructions? Just wondering.
What I am talking about is using inflections to add a meaning to an identifier such as a variable or type name.
For example:
native type integer
var x : integer = 12
var location : integers = 12, 5, 42
say 0th locationte to_string (( -te replaces "." operator. prints 12 ))
I think Perligata (Perl in Latin) is what you're looking for. :) From the article
There is no reason why programming
languages could not also use
inflexions, rather than position, to
denote lexical roles.
Here's an example program (Sieve of Eratosthenes):
#! /usr/local/bin/perl -w
use Lingua::Romana::Perligata;
maximum inquementum tum biguttam egresso scribe.
meo maximo vestibulo perlegamentum da.
da duo tum maximum conscribementa meis listis.
dum listis decapitamentum damentum nexto
fac sic
nextum tum novumversum scribe egresso.
lista sic hoc recidementum nextum cis vannementa da listis.
cis.
This is partially facetious, but... assembly language? Things like conditional jump instructions are often variations on a root ("J" for jump or whatnot) with suffixes added to denote the associated condition ("JNZ" for jump-if-not-zero, et cetera).
The excellent (dare I say fascinating) game-design language Inform 7 is inflected like English. But it's so closely integrated with a host of other design decisions that it's hard to peel away as a separate feature.
Anyone who is interested in language designs that are unusual but successful should check out Inform 7.
Presumably any programming language that uses natural language explicitly or closely as a basis, e.g., Natural-Language Programming. There was some research done at MIT into using English to produce high-level skeletons of programs, which is more in the realm of natural-language processing; the tool they created is called Metafor.
As far as I know, no existing language has support for, say, modifying or extending keywords with inflection. Now you've got me interested, though, so I'm sure I'll come up with something soon!
Of the 40 or so languages I know, the only thing that comes to mind is some rare SQL implementations which include friendly aliases. For example to select a default database after connecting, the standard is USE <some database name> but one I used somewhere which also allowed USING <some database name>.
FORTRAN uses the first letter of the name to determine the type of an implicitly-declared variable.
COBOL has singular and plural versions of its "figurative constants", e.g. SPACE and SPACES.
Python3.7 standard module contextvars has Context Variables, which can be used for inflection..
For my programming languages course, I'm trying to write some code snippets in languages that use pass by name or pass by value-result, preferably by default, but any language that even supports either of those would be fine. However, I haven't been able to find a single language that supports either of them. Does anyone know of a language that uses pass by value-result or pass by name? Preferably an imperative language.
The wikipedia article on evaluation strategy suggests that call-by-value-result is supported by fortran. Call-by-name is supported by algol 68.
I think C Macros are Pass-by-name (not the C language itself of course). I don't know of any pass-by-value-result languages I'm afraid (to be honest I had to do a web search to find out what it means!).
if you pass a variable to a fortran function and you modify it there, you also modify it in the calling program:
psuedocode:
int j = 1
print j
addOne(j)
print j
would output:
1
2
I think CLIPS expert system language would be pass by name.
Both Java and C are pass-by-value language.
C is clearly a pass by value language.
Java is always been told "primitives are passed by value, objects are passed by reference". But since java object is a reference at anytime, so it is actually a reference value.
Java Language specification tells this:
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#37472
Algol supports pass-by-name as you can find some explanation here
I was told that Ada supports pass-by-value/result but haven't tried out yet.
At the following URL: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsICacheVisitor is the following code chunk:
boolean visitDevice(in string deviceID, in nsICacheDeviceInfo deviceInfo);
I thought I was dealing with c++, but "in" is not a c++ keyword according to c++ keyword lists i looked up, nor is it a java keyword. So what's it there for and what's it mean?
It means that the parameter is an input parameter, meaning that it will be used but not modified by the function.
The opposite of an in parameter is an out parameter, which means that the parameter is going to be modified, but not explicitly returned. If you were to use an out parameter after a method that uses it, the value is going to (potentially) be different.
As nos points out in the comment, the page you linked to is describing a .idl, or Interface definition language, file. I'm not familiar with the IDL that Mozilla uses (but if you want to learn more, you can read about it here), but I am somewhat familiar with the Object Management Group's IDL, which says that in parameters are call-by-value, out parameters are call-by-result, and inout parameters are call-by-value/result.
The language is Mozilla's Interface Description Language (XPIDL).
The keyword "in" is described here: here
I've seen frameworks/SDKs for C/C++ that define macros to indicate whether a parameter is for input, output or both. I'm guessing that that's what's going on in your example.
For example, the Windows DDK does this for IN OUT and INOUT (if I remember right). When compiling these macros are defined to nothing, they have the potential to be defined to something useful for other tools (like an IDL compiler or a static analysis tool). I;m not sure if they still use these macros in the more recent DDKs.
Microsoft has taken this idea to an extreme with the SAL macros that give a very fine level of control over what behavior is expected for a parameter.