Wednesday, October 31, 2018
D language front-end merged with GCC 9; some sample D programs
The D Language Front-End Merged Into GCC 9 (phoronix.com)
HN thread about it.
D is a nice language, and fast both to compile and run. It has a wide range of features, but one can get started with it without learning all of them. It's fast both to compile and to run. Dev time is fast too.
I commented on the HN thread above too, giving a list of some of my own small D language programs (mainly command-line utilities) that can serve as a quick introduction to some of the different things that you can do with D.
I've reproduced the links to those D programs for the convenience of my readers, below:
"Here are a handful of D programs that use various features of the language and some of its libraries, on my blog. Most of them are simple command-line utilities to do various things. Readers may find them of use to get a flavor of the language and to know some of the kinds of things it can be used for."
A few of the posts are about interviews with D language people too.
Don't miss the interview where the creators or key people from the C++, Rust, D and Go languages talk to each other on a panel about some of the pros and cons of their respective languages - and the incident near the end of the video, involving Bjarne Stroustrup (the LangNext video below).
Here are those D-related posts:
Porting the text pager from Python to D (DLang)
Simple parallel processing in D with std.parallelism
Video: Interview: GoingNative 6: Walter Bright and Andrei Alexandrescu - D Programming Language
Using std.datetime.StopWatch to time sections of D code
Read from CSV with D, write to PDF with Python
Command line D utility - find files matching a pattern under a directory
min_fgrep: minimal fgrep command in D
num_cores: find number of cores in your PC's processor
Calling a simple C function from D - strcmp
Component programming in D - DDJ article by Walter Bright
Func-y D + Python pipeline to generate PDF
Interview: Ruminations on D: Walter Bright, DLang creator
file_sizes utility in D: print sizes of all files under a directory tree
Video: C++, Rust, D and Go: Panel at LangNext '14
deltildefiles: D language utility to recursively delete vim backup files
[DLang]: A simple file download utility in D
Getting CPU info with D (the D language)
- Vasudev Ram - Online Python training and consulting
I conduct online courses on Python programming, Unix / Linux commands and shell scripting and SQL programming and database design, with course material and personal coaching sessions.
The course details and testimonials are here.
Contact me for details of course content, terms and schedule.
DPD: Digital Publishing for Ebooks and Downloads.
Learning Linux? Hit the ground running with my vi quickstart tutorial. I wrote it for two Windows system administrator friends who were given charge of Unix systems. They said it made it easy for them to start using vi on Unix.
Check out WP Engine, powerful WordPress hosting.
Creating or want to create online products for sale? Check out ConvertKit, email marketing for online creators.
Own a piece of Americana: Jacob Bromwell: Legendary American Cookware
Teachable: feature-packed course creation platform, with unlimited video, courses and students.
See my posts about: Python * DLang * xtopdf
Check out my My ActiveState Code recipes (over 90 of them, mostly on Python)
Follow me on:
Saturday, April 15, 2017
Andrei Alexandrescu's AMA on IAmA reddit (C++ and D are some topics)
Just saw this today via a link while browsing articles about DLang (the D Language):
Andrei Alexandrescu's AMA on IAmA reddit
It starts off like this:
[ I am a member of Facebook's HHVM team, a C++ and D pundit, and a Machine Learning guy. Ask me anything!
Background:
My name is Andrei Alexandrescu. I've been a Research Scientist at Facebook for almost four years, during which I've worked on various projects mainly around Machine Learning and systems programming. In January I joined the HHVM project, which aims at improving the productivity and performance of PHP on Facebook's server infrastructure.
I've also written a couple of books: Modern C++ Design, C++ Coding Standards (together with Herb Sutter), and The D Programming Language, as well as some papers and articles. Some of my talks are on video (this is the most recent).
Looking forward to answering your questions! ]
I read part of the thread (so far); there are some interesting questions and answers in it, about both C++ and D (and maybe some other stuff I haven't seen yet). One such interesting point was this, where, in reply to a question, he says he likes to brag about inventing D's scope statement :-)
Some excerpts below:
[
chefox 17 points 3 years ago
What's the biggest lesson learned from D that you wish other languages would apply?
andralex 36 points 3 years ago
The scope statement. It's rare that I enjoy bragging about something, but I do like to brag that I invented a new control flow statement (which is awesome because they're so few!).
I think many languages implement some form of deferred execution, but most miss the point - Lisp's with-open-file, Java's try/finally, Go's defer, C#'s using are all sorely wanting.
]
Another one:
[ ... We have had an incredible time with compile-time evaluation in D for years, and I'm glad C++ "stole" that idea. ... ]
Another:
[
miotatsu 29 points 3 years ago
what has been your happiest moment with programming?
andralex 54 points 3 years ago
I remember moments when I'd run a little program again and again with slightly different inputs just to revel in the joy of having done the proper incantations that make the machine do this and that and the other, like a clumsy but loyal genie. I mentioned I wrote this floppy disk formatter - it gave me a lot of joy to be able to tell it the complicated sequence of things I wanted to get done, to see how it ended up carving magnetized trenches into the physical world.
]
Comment about the floppy driver formatter:
[
My first application was a keyboard driver in assembler. It used only 782 bytes of memory as opposed to the default of 4KB. I wrote it because I only had little RAM available.
My second application was a floppy disk formatter written in C++. It formatted 5.25'' floppies to 1.6 MB. Floppies were expensive and I couldn't afford many. Of course, they didn't retain information very well, but long-term retention wasn't at the top of my list :o).
]
About functional programming:
[
amzeratul 11 points 3 years ago
Lots of functional programming features are now available in languages such as C++ and D - what do you think are some of the functional features that we'll see incorporated in languages such as those over the next decade or two?
andralex[S] 17 points 3 years ago
There's talk about purity in C++, but beyond that I'm not sure whether there are plans for major FP-related additions.
Of the usual suspects present in FP languages, D notably misses pattern matching. It is in tension with OOP-style (first match vs. best match), and I'm not sure whether or not it's a fundamental feature of functional style. There are no plans to add such at this time.
]
[
p0nce 9 points 3 years ago
How much more productive do you think D can really be if adopted at C++ scale? Me and other enthusiasts I know are heavily biased by our positive solo experiences with it.
andralex[S] 10 points 3 years ago
Productivity and its variations are difficult to measure. Build speeds alone, at one order of magnitude speedup, are dramatic enough to exert a change of paradigm. For example, many people say dynamic languages are productive because they have the "right" execution model - save file, hit Refresh. If actual times for a compiled language drop to the point of offering the same model, I think a whole category of perceptions would change.
One thing I noticed with D is its "plasticity". Once you have a body of code that works in C++, the natural tendency is to be conservative about changing it: unit testing is tenuous, subtle failure scenarios upon changes are legion, not to mention build times etc. In D, it's a lot easier to mold and remold designs are you go because you know you wont be penalized for it.
]
[
Ingrater 10 points 3 years ago
Following the developement of D you get the feeling that way to many developement resources are spend on new features instead of finishing existing ones. For example a lot of work has been put into user defined attributes while other features are unfinished, unstable or not even usable (alias this, shared, export, structs). Whats your opinion on this?
andralex[S] 14 points 3 years ago
I agree that we should focus more on completing, streamlining, and using what we've got. This is happening already - it's been a while since quality has been at the top of our list, and the positive PR has been visibly improving.
Now that we have more resources there is some amount of parallel work we could do, and the mixed blessing with volunteer work is people work on what they find interesting, not necessarily what's best to do at the moment. This has been a challenge, but at the same time a good problem to have.
]
[
jfernand 10 points 3 years ago
Andralex,
No question to ask, but the comment that I carry the D language book with me at all times, and re-read it like it is a novel; I love every line of code I write in D, and the language and its design choices make me a better programmer the more I understand them. D simply makes sense, and it is a shame that it does not have more traction... I am an seasoned C/C++/Perl programmer, and D is in many ways the epitome of the history of languages, in my opinion.
andralex[S] 9 points 3 years ago
Thank you! No worry, we'll figure out the traction issue :o).
]
There's a lot more to the thread, check it out. Here it is again:
Andrei Alexandrescu's AMA on IAmA reddit
- Vasudev Ram - Online Python training and consulting Get updates (via Gumroad) on my forthcoming apps and content. Jump to posts: Python * DLang * xtopdf Subscribe to my blog by email My ActiveState Code recipesFollow me on: LinkedIn * Twitter Are you a blogger with some traffic? Get Convertkit:Email marketing for professional bloggers
Saturday, April 8, 2017
The reference D compiler is now open source (dlang.org)
Just saw this discussion on HN:
DMD, the reference D compiler is now open source (dlang.org)
It is about this news about the D language:
dmd Backend converted to Boost License
I read part of the discussion, and also commented. As often happens, though the original post is about the change in the licensing of the back=end of the DMD compiler (Digital Mars D), the thread devolved (partly at least) into a discussion of the pros and cons of D versus some other languages, and that kind of thread is often interesting.
Updating the post to add:
- Link to this post on programming.reddit.com about the news:
The Official D Compiler Is Now Free (as in "freedom")
- As user bionsuba says there:
[ bionsuba[S] 30 points 4 hours ago
The front end as been Boost licensed for several years now. But now the backend has been relicensed thanks to Symantec giving their permission.
This has big implications for the language as a whole, as the compiler can now be included in Linux package managers. Meaning, D programs can be distributed on those same package managers. There's also the possibility that DMD can become part of the default packages on a distro! ]
And Andrei Alexandrescu (of Modern C++ Design fame), who now works with Walter Bright on the D language, adds:
[ andralex 16 points 3 hours ago
We will discuss more details and implications of the impact of open sourcing the compiler at DConf in Berlin in May. Registration is open! ]
Update 2 to add:
I'm putting below, an Ask HN thread that I had started some months ago. It got some interesting replies:
Ask HN: What are you using D (language) for?
The replies give some examples of non-trivial things that D can be used for.
Update 3 to add:
As Walter Bright say here, it's the #1 story on HN at the moment (and for a while now).
- Vasudev Ram - Online Python training and consulting Get updates (via Gumroad) on my forthcoming apps and content. Jump to posts: Python * DLang * xtopdf Subscribe to my blog by email My ActiveState Code recipesFollow me on: LinkedIn * Twitter Are you a blogger with some traffic? Get Convertkit:Email marketing for professional bloggers
Wednesday, December 21, 2016
[Video] Interview: All Things D (programming language) - A Conversation with Andrei Alexandrescu
This is a video about the D language that I watched recently, which I found informative and interesting:
All Things D (programming language) - A Conversation with Andrei Alexandrescu
It's an interview of Andrei, I think by the same interviewer (who is not seen in this video) who did the interview of people from the D, Rust, Go and C++ teams, at the LangNext '14 event, the video of which I posted about here earlier:
Video: C++, Rust, D and Go: Panel at LangNext '14
Andrei talks about the past, features and future of D. The video is also embedded below.
- Vasudev Ram - Online Python training and consulting Get updates (via Gumroad) on my forthcoming apps and content. Jump to posts: Python * DLang * xtopdf Subscribe to my blog by email My ActiveState Code recipesFollow me on: LinkedIn * Twitter Managed WordPress Hosting by FlyWheel
Sunday, November 27, 2016
Video: Interview: GoingNative 6: Walter Bright and Andrei Alexandrescu - D Programming Language
I watched this video (from 2013) a few days ago:
GoingNative 6: Walter Bright and Andrei Alexandrescu - D Programming Language
Going Native [1] is a tech event, and I guess 6 refers to the 6th year or edition of it. I first saw this video on Channel 9, one of Microsoft's technology sites. That site has multiple links to the video, including downloadable, in different qualities, so you may want to check out getting it from there. [2]
[1] There seems to be rising interest in "native" (programming) languages these days (before the rise of "scripting" languages, all languages were native, i.e. they ran, after compilation, on the "metal" (i.e. the CPU), not on a language VM or interpreter, and we just called them languages, no fancy-shmancy names, ha ha :). Part of the reason for the rise in interest, as mentioned in the video, is that we are entering (or have entered) a world of multi-core and concurrency, and due to Moore's law ending (?) Anyway, native languages like D, Go and Rust are picking up these days, whatever the reason. I've used native languages like Pascal and C a lot at work earlier, so I welcome this return of greater interest in native languages, though I'm not stopping using languages like Python anytime soon either.
[2] And to download the video at the command line, check out youtube-dl, a YouTube downloader in Python. Yes, downloading a video about native languages with a tool written in a scripting language - go figure :)
The video shows an interviewer talking to both Walter Bright and Andrei Alexandrescu. Walter, who developed the first native C++ compiler, is the original creator of the D programming language and Andrei, who was a C++ expert and book author, joined him some years later to help in developing the language. The interview was somewhat wide-ranging and a bit long, and quite interesting. Many aspects of the language and the plans and in-progress work for it were talked about.
The video is also embedded below.
Happy holidays to my readers.
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Black Flyday at Flywheel Wordpress Managed Hosting - get 3 months free on the annual plan.
Subscribe to my blog by email My ActiveState recipes
Saturday, October 29, 2016
Red-Lang: Live-coding of a clock demo, EVE-style
Clock live-coding image attribution
This is cool. I was just reading this HN thread:
Eve: Programming designed for humans (witheve.com)
which, BTW, is at the top of the HN front page at the time of this writing, and is about a new programming language called Eve from Chris Granger (and maybe others).
The Eve web site.
The home page of the Eve site says: [ Eve is a programming language and IDE based on years of research into building a human-first programming platform. From code embedded in documents to a language without order, it presents an alternative take on what programming could be - one that focuses on us instead of the machine. ]
Chris Granger may be known to some as the person behind Light Table, an innovative "open source IDE that lets you modify running programs and embed anything from websites to games", that was also discussed quite a bit on HN some time ago. I'm guessing Eve builds upon Light Table, for the IDE part of it.
[ Update: Chris's HN profile says: Co-founder of Kodowa, the company behind Eve and Light Table. YC alum. Ex-Microsoft Program Manager for C# and VB in Visual Studio. Chris also says in this comment on the HN thread, that the language part of Eve (it has other parts too) is a variant of datalog. ]
I had not checked out Light Table but I had briefly checked out Noir (another project by Chris), a micro-framework that allows you to rapidly develop web sites in Clojure, and had liked what I saw of it.
Anyway, in the HN thread about Eve, someone posted a link to a demo of live-coding a digital clock, using the Red language, which I had also checked out some months ago. I found Red and its goals interesting; reducing the complexity of modern software development is a big goal, another is being cross-platform (to desktop and server and mobile) and being a full-stack language - that last point, a bit like the D language - i.e. from being able to use assembly (Red may not supports that, but D does), all the way up to high levels of modeling power - but Red does have a lower level language, which Red is in fact built upon, called Red/System, which is supposed to be at the conceptual level of C - but with Red-style syntax). Red is at a somewhat early stage of development - v0.6 or so, but usable. I could even compile a simple Red program to an EXE and run the EXE - it was quite small too. Yes, RED has both an interpreter and a compiler - and like REBOL, the whole Red package is astonishingly small in size.
Red is a sort of successor to REBOL, but by a different person / team. I had played around with REBOL some years earlier and liked it too.
Here is the clock live-coding demo in Red - the drawing of the clock actually updates on the screen, live, as the code for the clock is being written. This works due to some language features of Red, including, as they say on that page:
[ Yes, livecoding (using native widgets!) in Red can be that simple. As you can see, there's no built-in "livecode" widget or feature, it's an emergent behavior resulting from the combination of existing Red features, homoiconicity being the most fundamental. ]
Interestingly, as the Wikipedia article (linked in the preceding sentence) says, assembly language (at least for systems using Von Neumann architecture) can also be considered to be homoiconic - because both code and data are just bytes in memory.
The image at the top of the post is a screenshot I took, of when the live-coding, and hence the (iterative and exploratory) drawing of the clock was in progress.
The image below is another screenshot taken after the clock was fully drawn. If you load that page in your browser, you can see the whole thing happening.
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes Managed WordPress Hosting by FlyWheel
Tuesday, September 20, 2016
Calling a simple C function from D - strcmp
D => C
It's quite useful to be able to communicate between modules of code written in different languages, or, in other words, to be able to call code in one language from code in another language. Some of the reasons why it is useful, are:
- some functions that you need may already be written in different languages, so it may be quicker to be able to call cross-language from function f1 in language L1 to function f2 in language L2, than to write both f1 and f2 in L1 (or in L2) from scratch;
- the function f2 that you need may not be as easy to write in language L1 as it is in language L2 (or you don't have people who can do it in L1 right now);
- f2 may run faster when written in L2 than in L1;
- etc.
I was looking into how to call C code from D code. One source of information is this page on the D site (from the section on the language spec):
Interfacing to C
Here is an example of calling a simple C function, strcmp from the standard C library, from a D program, adapted from information on that page:
/* File: call_strcmp.d Purpose: Show how to call a simple C string function like strcmp from D. Author: Vasudev Ram Copyright 2016 Vasudev Ram Web site: https://vasudevram.github.io Blog: http://jugad2.blogspot.com */ extern (C) int strcmp(const char* s, const char* t); import std.stdio; import std.string; int use_strcmp(char[] s) { // Use toStringz to convert s to a C-style NULL-terminated string. return strcmp(std.string.toStringz(s), "mango"); } void main(string[] args) { foreach(s; ["apple", "mango", "pear"]) { // Use dup to convert the immutable string s to a char[] so // it can be passed to use_strcmp. writeln("Compare \"", s.dup, "\" to \"mango\": ", use_strcmp(s.dup)); } }I compiled it with DMD (the Digital Mars D compiler):
$ dmd call_strcmp.dand ran it:
$ call_strcmp Compare "apple" to "mango": -1 Compare "mango" to "mango": 0 Compare "pear" to "mango": 1The output shows that the C function strcmp does get called from the D program, and gives the right results, -1, 0, and 1, for the cases where the first argument was less than, equal to, or greater than the second argument (in sort order), respectively.
Of course, not all kinds of calls from D to C are going to be as easy as this (see the Interfacing reference linked above), but its nice that the easy things are easy (as the Perl folks say :).
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes
Monday, September 19, 2016
Programming Languages Beacon (what large apps written in what languages)
Java C# Python C++ PHP ASM C
The Programming Languages Beacon (PLB) is an interesting site that I came across today, via this comment on John D. Cook's blog. (The comment is by Cook himself, in reply to another comment on his post).
The PLB page has a big table showing the main programming language(s) that many large well-known software products, such as operating systems, browsers, office suites, and others, are written in.
Some of the products mentioned in the table: Windows, Linux, Mac OS, HP-UX, iOS, Android, KDE, MS Office, LibreOffice, Oracle, MySQL, Hadoop, Firefox, Safari, ...
No prizes for guessing what language(s) the majority of the products listed are written in :)
The beacon site is maintained by Vincent Lextrait.
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes Managed WordPress Hosting by FlyWheel
Thursday, September 8, 2016
"Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, ...
By Vasudev Ram
"Please don't assume Lisp is only useful for Animation and Graphics,
AI, Bioinformatics, B2B and E-Commerce,
Data Mining, EDA/Semiconductor applications,
Expert Systems, Finance,
Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom,
and Web Authoring just because these are the only things they happened to list." --Kent Pitman
One could say somewhat the same about Python ...
Image attributions:
Utah teapot
Shopping cart icon
Semiconductor
Dollar
Telecom
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes
Wednesday, August 31, 2016
Interview: Ruminations on D: Walter Bright, DLang creator
By Vasudev Ram
I read this interview yesterday:
Ruminations on D: An Interview with Walter Bright (creator of the D programming language).
(Walter Bright (Wikipedia))
The interview also links to this talk between Walter and Andrei Alexandrescu, of Modern C++ fame, who joined Walter to work on D (after working at Facebook for some time)) about a D project, warp (a C++ preprocessor), that Walter did for Facebook; the talk is about the D benefits Walter found while working on the project (such as the ease of changing the data structures to try different approaches, and how the ranges and the algorithms that operate upon them are somewhat decoupled).
(Andrei Alexandrescu (Wikipedia))
HN thread about the interview.
You can also check out this video, about the creators or key team members of 4 languages, C++, D, Golang and Rust, talking at LangNext '14:
Video: C++, Rust, D and Go: Panel at LangNext '14
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes
Friday, August 5, 2016
The D Language Playground site
The D language playground site:
is a web site (created somewhat recently, IIRC), where you can write or paste in a chunk of D code into a text box, click Run, and it will run it on their server, and send back the results to be displayed. It also has a tour of the language, and you can go from one example to another, and just run, or modify and run, each of them. So the same site serves both as an online sandbox to experiment with D language snippets, and as an interactive tutorial for D. In both these ways it is similar to the Go language playground/tour site. Either or both are worth checking out, if you are interested in those languages.
- Vasudev Ram - Online Python training and consulting My Python posts Subscribe to my blog by email My ActiveState recipes
Saturday, December 19, 2015
Python doesn't know the meaning of life :-)
Attribution of above image
I was checking out the repr() and __repr__() functions / methods of Python (in the process of creating an exercise for one of my students), when I came across this interesting 'feature' of Python:
I did this at the Python interpreter prompt (in both 2.7 and 3.4):
>>> ''.__repr__() # Call the dunder repr method on an empty string.
"''"
>>>
(Got the expected output - the representation of the empty string.)
Similarly for a list, a tuple, etc.:
>>> [].__repr__()
'[]'
>>> ().__repr__()
'()'
But when I did this:
>>> 42.__repr__()
I got this:
File "<stdin>", line 1
42.__repr__()
^
SyntaxError: invalid syntax
So, it looks like Python does not know the meaning of life :-)
Jokes apart, I also tried this (actually, before trying 42):
>>> 1.0.__repr__()
'1.0'
which worked. And the only difference between the example above that worked (1.0), and the two that did not (1 or 42), is that the latter two use an int, and the former uses a number with a decimal point.
But both also use the dot as the attribute access operator, which leads me to think that this is the reason for the issue (for ints): there is an ambiguity between interpreting 1.something as 1.other_decimal_digits (making it a floating point number) and as 1.some_attribute (making it an attribute access on an object) (because 1, like (almost) everything in Python, is an object (of type int), as can be seen by doing:
>>> dir(1)
and
>>> type(1)
Interested to know if anyone has a better explanation of this, and also of whether the same issue/anomaly, if it is one, occurs in any other languages, or if not, why not.
- Vasudev Ram - Online Python training and programming Signup to hear about new products and services I create. Posts about Python Posts about xtopdf My ActiveState recipes
Sunday, March 29, 2015
Video: The Roots of Go (the 45 year old language): Talk at GopherCon India 2015
Saw this via Baishampayan Ghose's Twitter account (@ghoseb).
It is a video of a talk he gave, titled The Roots of Go, at GopherCon India 2015.
I only watched part of the video (so far) but it seems good.
I may update this post with more comments after watching the video completely.
The video is also embedded below.
- Vasudev Ram - Online Python training and programming Dancing Bison EnterprisesSignup to hear about new software or info products that I create. Posts about Python Posts about xtopdf Contact Page
Friday, December 12, 2014
Streem, new programming language by Ruby creator, Matz
Saw this thread on Hacker News today:
Streem – a new programming language from Matz (github.com)
Here's the Github project for the Streem language.
It says there that it is still in the design stage, and not working yet. But given that it is by Matz, creator of the Ruby language, it should be worth keeping an eye on. There is one example at the Streem site that is UNIX-like, and another that shows some influence of Ruby syntax.
- Vasudev Ram - Dancing Bison EnterprisesClick here for email about new products and services from me. Contact Page
Friday, April 25, 2014
Python variables can have types as values

I came across this article by Peter Norvig:
Design Patterns in Dynamic Languages
(Peter Norvig is Director of Search at Google and a highly accomplished computer scientist.)
Haven't read the article fully yet, but scanned it a bit, and one line in particular interested me:
"A variable can have a type as a value"
That line is on the page with the heading: "First-Class Dynamic Types"
So I thought of checking this in Python - that section of the article seems to be about Lisp and Dylan (the programming language)).
Here's some code I used to check whether Python variables can have types as values - I typed it in the Python interpreter, so both the input and the output appear below:
>>> a = int >>> type(a) <type 'type'> >>> print a('3') + 4 7 >>> b = str >>> print b(12) * 5 1212121212 >>> class Foo: ... def bar(self): ... print "in Foo.bar()" ... >>> f = Foo >>> f().bar() in Foo.bar() >>>And here's a couple more lines which give a clue why the above works:
>>> id(int) 505548800 >>> id(a) 505548800 >>> id(str) 505571224 >>> id(b) 505571224Note that the names int and str have valid id()s, and that id(a) == id(int), and id(b) == id(str).
So it seems that variables in Python can have values that are types. Of course, the id() stuff I did above indicates that it will work for all Python types if it works for one, since "a = int" binds the name a to the same object that the (built-in) name int is bound to. That's my guess, anyway. Interested to see if anyone has any different ideas or a better explanation.
And speaking of Peter Norvig, here's another article by him about Albert Einstein:
'05 Annual Performance Review: Albert Einstein
- Vasudev Ram - Dancing Bison Enterprises
Contact Page
Sunday, April 20, 2014
Nice post and discussion about Delphi
Saw this interesting post and subsequent Hacker News thread on Delphi:
Post:
Delphi, why won't it just die?
HN thread about the post.
- Vasudev Ram - Dancing Bison Enterprises
Contact Page
Saturday, June 1, 2013
Video: Fireside chat, Go team at Google I/O 2013
Watch "Google I/O 2013 - Fireside Chat with the Go Team" on YouTube
Watched some of it. Audio not very good (on mobile) but can still hear a good amount. Probably better on desktop.
Thursday, February 21, 2013
Lua inside Python, Python inside Lua - Lunatic Python
(Fixing the no newlines issues in the post, with this edit. If any reader still notices any issue with formatting, please leave a comment and I'll check it again - thanks.)
Lunatic Python - Labix
As the title of this post says, Lunatic Python (nice name - see below for why :-), is a software bridge, that enables two-way communication between Python and Lua.
From the site: "Being two-way means that it allows Lua inside Python, Python inside Lua, Lua inside Python inside Lua, Python inside Lua inside Python, and so on."
I only saw it today, so have not tried it out much yet, but from reading some of the code examples, it looks pretty interesting. Here are a few examples from the site (pasted from mobile, some characters may get changed, check site for exact code):
[
Lua inside Python A basic example. >>> import lua >>> lg = lua.globals() >>> lg.string>>> lg.string.lower >>> lg.string.lower("Hello world!") 'hello world!' Now, let's put a local object into Lua space. >>> d = {} >>> lg.d = d >>> lua.execute("d['key'] = 'value'") >>> d {'key': 'value'} Can we get the reference back from Lua space? >>> d2 = lua.eval("d") >>> d is d2 True Good! Is the python interface available inside the Lua interpreter? >>> lua.eval("python") Yes, it looks so. Let's nest some evaluations and see a local reference passing through. >>> class MyClass: pass ... >>> obj = MyClass() >>> obj <__main__.MyClass instance at 0x403ccb4c> >>> lua.eval(r"python.eval('lua.eval(\"python.eval (\'obj\')\")')") <__main__.MyClass instance at 0x403ccb4c> Are you still following me? Good. Then you've probably noticed that the Python interpreter state inside the Lua interpreter state is the same as the outside Python we're running. Let's see that in a more comfortable way. >>> lua.execute("pg = python.globals()") >>> lua.eval("pg.obj") <__main__.MyClass instance at 0x403ccb4c>
]
Though it is an experimental project, the author of Lunatic Python, Gustavo Niemeyer, says that it is being used in some real world applications.
Lua.
Lua on Wikipedia.
Lua is a (buzzwords ahead :) cross-platform (*), extensible, multi-paradigm, lightweight scripting language.
It is used a lot in real world applications, including games, an Adobe product, and other areas.
Lua means moon in Portuguese (it was developed at an institute in Brazil), that's why the name Lunatic Python is a good one, since lunatics are supposed to be influenced by the moon ...
I had first come across Lua some years ago when checking out various new or less known programming languages. Tried it out a bit at the basic level, not the extensibility aspects.
(*) It seems to have developed a lot since then, at least in platform support; the Lua home page says it runs on OS's from many mobile ones up to mainframes. When I first saw it, it only worked on Linux and Windows, IIRC.
- Vasudev Ram
Wednesday, February 6, 2013
Topaz, a new Ruby written in Python
Announcing Topaz: A New Ruby — Topaz 0.1 documentation
Seen via a post by @jnoller (Jesse Noller of the PSF) on Hacker News. It is the top post there right now.
Topaz is written in Python, using RPython, the tool that PyPy is also written in. They claim it has a fast garbage collector and a JIT. However, it is in an early version now, so not complete.
Some of the developers of other Ruby implementations, such as JRuby and Rubinius, have advised the developers of Topaz.
Interesting ...
PyPy itself is also interesting because it is an implementation of Python written in (R)Python, and yet, I've read somewhere that it runs some Python code faster than CPython.
http://pypy.org/
- Vasudev Ram
Monday, January 7, 2013
Introduction to Go: Dr. Dobbs: a five-part series
Introduction to Go | Dr Dobb's
It is by Mark Summerfield, a software developer and trainer who has also written books on Qt and Python.
- vr
dancingbison.com