News for hackers. Stuff that matters.
Re:Ferret: a Lisp implementation for real time embedded cont... by garganzol on Tuesday July 31, 2018 @10:00AM (#17653156)
Where is the source code of a compiler? It looks like it's written in Java but there are no source code files in corresponding GitHub repo.
Re:Ferret: a Lisp implementation for real time embedded cont... by phoe-krk on Tuesday July 31, 2018 @10:08AM (#17653224)
ALL of the code seems to be stored inside the org-mode file, https://github.com/nakkaya/ferret/blob/master/ferret.org - which is the most unusual form of source code organization that I have ever seen.
Re:Ferret: a Lisp implementation for real time embedded cont... by antt on Tuesday July 31, 2018 @10:24AM (#17653373)
There's singles of us!

If you want to extract it run M-x org-babel-tangle and you will end up with the usual source files and directories installed relative to the location of the org file.

I doubt there's a dozen people in the world that do it. But it is surprisingly useful and powerful when you get used to it. If anyone in Melbourne is interested in learning about this I have been toying with the idea of running a workshop on it.

I'm in the process of getting the detangle working for noweb mode. The current implementation fakes it with regex which force you to write code linearly instead of literately. But even if you can't detangle arbitrarily nested code it's magic to see changes in a source file appear in the right source code block.

Re:Ferret: a Lisp implementation for real time embedded cont... by DennisP on Tuesday July 31, 2018 @12:05PM (#17654375)
So you're doing literate programming with org-mode. That's pretty nifty.

I'm on the opposite side of the planet but I'd be interested, if you did an article or video on whatever you would teach in the workshop.

Re:Ferret: a Lisp implementation for real time embedded cont... by th0ma5 on Tuesday July 31, 2018 @12:27PM (#17654547)
I know the rather spiffy project http://thi.ng uses org mode for literate programming and web site generation all from the source code. It doesn't seem to be all one big file, but I think each component may be a file.
Re:Ferret: a Lisp implementation for real time embedded cont... by throwaway427 on Tuesday July 31, 2018 @03:27PM (#17656258)
Been doing emacs config in org for a long time. I think it's more common than you think, at least for that purpose.
Re:Ferret: a Lisp implementation for real time embedded cont... by antt on Tuesday July 31, 2018 @08:17PM (#17658529)
Quite possibly, outside of a post every two weeks or so on HN I have never met anyone else who uses it.

Though I have met a few people who use org mode as an organizer/planner.

Re:Ferret: a Lisp implementation for real time embedded cont... by Touche on Tuesday July 31, 2018 @11:16AM (#17653824)
How do you deal with having to scroll such a large file? That's the biggest turn-off to literate programming for me. I don't like code files more than a couple hundred lines of code. Search isn't enough for me.
Re:Ferret: a Lisp implementation for real time embedded cont... by Jtsummers on Tuesday July 31, 2018 @11:26AM (#17653933)
Org mode will let you collapse trees and source blocks. You can also narrow the view to a sub tree. This makes navigation much easier.
Re:Ferret: a Lisp implementation for real time embedded cont... by heavenlyblue on Tuesday July 31, 2018 @11:40AM (#17654113)
So how is navigating the file tree any different from navigating the source code tree?

Just don’t tell me “you can see the context” as any proper codebase would probably not be linear in code flow anyway.

Re:Ferret: a Lisp implementation for real time embedded cont... by Jtsummers on Tuesday July 31, 2018 @12:10PM (#17654416)
I mean, it isn't, if you organize your file identically to the source tree. But I break it out differently when I use this approach. I'll use the noweb references and scatter my code across the document in a logical way that's not reflective of the generated source tree.

For instance, I group all include or equivalent statements in an appendix, rather than within the primary code discussion. If a block of code can't be directly reused, but for some reason needs to be in every (or several) source files (think standard boilerplate), I'll write it once in a place that makes sense, and reference it from all the places where it actually gets tangled into the output.

Additionally, I include the Makefile (or whatever equivalent) and other scripts within this same document. Learning docker? Make a dockerfile in here, fully annotated, along with the shell commands to actually deploy it.

Mine will only mirror the original source tree if it's:

Very simple.

I've imported a bunch of code into it and don't, yet, know how to break it down.

An example C project may look like:

  * Purpose Statement
  * README
  * Usage
  This program can be executed from the command line by calling:
  #+BEGIN_EXAMPLE
    $ ./foo
  #+END_EXAMPLE
  It accepts the following command line parameters:
  - =-c= :: something
  - =-d= :: something else
  ** Implementation
  To process the command line flags we use <some library>.
  it has the following API calls...

  Here's the code for processing our commands...
  * Business Logic
  We communicate with the server via some REST API described in <location>
  and <library> to make the calls.
  -- Here I'd intermingle the REST API I'm using and the C API I'm producing
  -- for my own consumption, or something similar.
  * Code that's not fully organized yet
  ** Main Function
  This is the entry point, blah, blah, blah:
  #+BEGIN_SRC c :noweb yes :tangle src/main.c
  #+END_SRC
  * Appendix: Includes
Re:Ferret: a Lisp implementation for real time embedded cont... by jacobush on Tuesday July 31, 2018 @11:48AM (#17654214)
That it's not different is kind of a good point?

Some people use several Emacs windows (or frames or whatever) but all of them peeking into the same file, but in to different locations of it.

Re:Ferret: a Lisp implementation for real time embedded cont... by ehaliewicz2 on Tuesday July 31, 2018 @02:00PM (#17655436)
If it's all the same, why use separate files?
Re:Ferret: a Lisp implementation for real time embedded cont... by emidln on Tuesday July 31, 2018 @04:09PM (#17656634)
When your IDE (or Emacs in this case) offers go jumping/searching functionality, it doesn't really matter how many files your code is in. When I used bare vim, I cared a lot more about code organization than I do with an IDE that makes jumping around the codebase easy.
Re:Ferret: a Lisp implementation for real time embedded cont... by omaranto on Tuesday July 31, 2018 @01:48PM (#17655309)
That's called literate programming. Maybe the most famous example is the source code for TeX, a single ~25,000 line file (http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.we...) that can be used to make a TeX compiler, or produce a book explaining the implementation.
Re:Ferret: a Lisp implementation for real time embedded cont... by eigenspace on Tuesday July 31, 2018 @10:29AM (#17653412)
I actually just started dong this a few days ago and I’m loving it so far. I have it configured so that every time I save, emacs runs org-tangle and all my code ends up in the proper directories but I never have to touch it there, I can just stay in org mode and keep different ‘files’ of code in different collapsible sections making moving around much easier!
Re:Ferret: a Lisp implementation for real time embedded cont... by antt on Tuesday July 31, 2018 @10:35AM (#17653473)
Look at org-babel-detangle and have your mind blown[0].

[0] Mostly, the current implementation works only with source blocks that are linearly added one after the other and don't use the <<noweb reference>> in code blocks.

Re:Ferret: a Lisp implementation for real time embedded cont... by tincholio on Tuesday July 31, 2018 @10:35AM (#17653475)
I had a similar setup, but ended up coding a toggle for it, as it can get rather long as your source grows. In case you find it useful:

        ;; Tangle Org files when we save them
    (defun toggle-org-tangle-on-save()
      (interactive)
      (if (bound-and-true-p org-tangle-on-save)
          (setq-local org-tangle-on-save nil)
        (setq-local org-tangle-on-save t))
      (message (if org-tangle-on-save "Enabled tangling on save" "Disabled tangling on save")))
Re:Ferret: a Lisp implementation for real time embedded cont... by Quequau on Tuesday July 31, 2018 @10:11AM (#17653246)
Using org-mode for literate programming isn't entirely unheard of.
Re:Ferret: a Lisp implementation for real time embedded cont... by phoe-krk on Tuesday July 31, 2018 @10:14AM (#17653275)
I guess I had never seen literate programming taken to such an extreme before. This was an actual surprise for me.
Re:Ferret: a Lisp implementation for real time embedded cont... by antt on Tuesday July 31, 2018 @10:31AM (#17653433)
This has been my go-to way of programming anything where I'm the primary person responsible for it.

With pandoc you get a system that can export to any format under the sun. The highlight so far was exporting a problematic code portion with the literate explanation around it and a pretty basic asymptotic analysis in latex to docx, code highlighting, math formulas, tables all worked without human intervention. It ended up in a power point that I'm told was very well received.

Re:Ferret: a Lisp implementation for real time embedded cont... by enitihas on Tuesday July 31, 2018 @12:20PM (#17654492)
Just curious, how does github manages to render org files so flawlessly, including embedded code snippets. I thought emacs was the only popular environment supporting org files.
Re:Ferret: a Lisp implementation for real time embedded cont... by eigenspace on Tuesday July 31, 2018 @02:18PM (#17655623)
Github seems to play quite well with Org. Little known fact: If you give your repo a README.org instead of a README.md, github will show that file just like how it shows a regular README.md.
Re:Ferret: a Lisp implementation for real time embedded cont... by peatmoss on Wednesday August 01, 2018 @09:25AM (#17662244)
Unfortunately, the same can't be said of Bitbucket. At one point I voted for or commented on a feature request for it, and I pretty routinely get notified when someone else discovers the lack of org-mode support on Bitbucket.

At this point, I'm convinced Atlassian hates happiness, or there is some shameful architectural reason why they cannot support more than Markdown for their READMEs. Given the number of vociferous responses to that feature request, there would appear to demand.

Re:Ferret: a Lisp implementation for real time embedded cont... by omaranto on Wednesday August 01, 2018 @12:45PM (#17664230)
> I thought emacs was the only popular environment supporting org files.

Pandoc has a pretty decent Org Mode parser and writer.

Re:Ferret: a Lisp implementation for real time embedded cont... by nine_k on Tuesday July 31, 2018 @10:11AM (#17653244)
There's a "building from sources" section on https://ferret-lang.org/, but I could not easily detect where the source is on github.

Update: It needs to be extracted from an org file, and by default Github renders the org file so that the source is not visible.

Re:Ferret: a Lisp implementation for real time embedded cont... by gvb on Tuesday July 31, 2018 @01:43PM (#17655254)
Or click the "raw" button on the github source page.

https://raw.githubusercontent.com/nakkaya/ferret/master/ferr...

Re:Ferret: a Lisp implementation for real time embedded cont... by zellyn on Tuesday July 31, 2018 @01:02PM (#17654877)
Do you not see all the source code in https://github.com/nakkaya/ferret/blob/master/ferret.org?
Re:Ferret: a Lisp implementation for real time embedded cont... by rileyphone on Tuesday July 31, 2018 @10:07AM (#17653219)
It's in ferret.org, apparently.
Re:Ferret: a Lisp implementation for real time embedded cont... by nanomonkey on Tuesday July 31, 2018 @01:16PM (#17655018)
The first time I came across this it was touted as Clojure that compiled down to C++11. Now I'm seeing it listed as a generic lisp. I'm curious if that's due to the limitations of writing for embedded systems (using d-list instead of hash tables, memory management, etc.) or are there other deviations?
Re:Ferret: a Lisp implementation for real time embedded cont... by kimi on Tuesday July 31, 2018 @01:50PM (#17655318)
IIRC it used to be a fairly complete reimplementation of Clojure. I toyed with the idea of using it to cross-compile to Golang.
Re:Ferret: a Lisp implementation for real time embedded cont... by nakkaya on Thursday August 02, 2018 @06:29AM (#17670422)
You are right. It is due to limitation of writing for embedded systems. I try to keep everything as close to Clojure as possible but some stuff is just not possible on embedded systems or behave a little bit different.
Re:Ferret: a Lisp implementation for real time embedded cont... by bsder on Tuesday July 31, 2018 @02:55PM (#17655969)
Given that this seems to be a transpiler, why go to C++ instead of C?

What feature of C++ does this need that is so compelling as to cut it off from use on straight C?

Re:Ferret: a Lisp implementation for real time embedded cont... by nakkaya on Thursday August 02, 2018 @06:53AM (#17670526)
If I were to go with C I would have to reimplement OOP machinery required for an object system. OOP also makes memory management a non issue. Functions are first class citizens in Lisp so functors/lambdas makes it real easy to create closures. std::atomic combined with Clojure semantics makes sure there no race conditions. std::thread / std::future makes multi threaded programming much easier. Templates help with picking and choosing which components to include (i.e there are multiple memory managers to pick from.). etc. etc. Non of the above is essential and can be done in C but why bother, GCC/LLVM people are much better at this then I can be including platform specific tricks for different architectures. Modern C++ is very close to Lisp after all it only takes 6 passes over the Clojure code to generate C++ code. (Compiler makes more than 6 passes but others are for optimization.)
Re:Ferret: a Lisp implementation for real time embedded cont... by m1n1 on Wednesday August 01, 2018 @01:54PM (#17665031)
Maybe that's a solved problem so that was outside the scope/focus? https://isocpp.org/wiki/faq/compiler-dependencies#convert-to...
Re:Ferret: a Lisp implementation for real time embedded cont... by BrendanD on Tuesday July 31, 2018 @11:02AM (#17653697)