💾 Archived View for dioskouroi.xyz › thread › 29399862 captured on 2021-12-03 at 14:04:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Excel-Virtual-Machine: C Compiler which targets Excel

Author: davikrr

Score: 299

Comments: 65

Date: 2021-12-01 02:11:25

Web Link

________________________________________________________________________________

nazgulsenpai wrote at 2021-12-01 02:49:48:

A2 acting as standard input, and cell B2 acting as standard output.

This made me literally laugh out loud for way too long. This is the dumbest and most awesome thing I've seen in a while. I love it.

Also doesn't seem to have been modified for 5 years.

Infernal wrote at 2021-12-01 02:54:51:

“To ensure accuracy, do not disturb the spreadsheet before it is finished recalculating.”

Sage advice indeed.

hulitu wrote at 2021-12-01 07:28:40:

I learned it the hard way. Had an excel template which analised results from a test. It runs for 30-60 minutes depending on the amount of data. If you have another file open in excel and hope to work on it, forget it. Tried it, all data in the other spreadsheet was corrupted (results written in the wrong sheets due to other window being active). The only wise thing was to wait. This was helped by the fact that excel was using one core fully and the other 3 were thermal throtled so the laptop was unusable.

djxfade wrote at 2021-12-01 09:27:32:

That's insane. Excel definetly didn't sound like the right tool for that job

t0suj4 wrote at 2021-12-01 11:10:31:

I'm pretty sure there would be a market for a tool that transpiles Excel into literally anything else

ajuc wrote at 2021-12-01 15:36:54:

In 2 separate companies I wrote java software that loaded .xlsx files with thousands of rows of rules written in 2 different proprietary ill-specified languages that were then interpreted by the java program.

Excel Oriented Programming is a thing.

mattarm wrote at 2021-12-01 23:35:47:

Yes it is.

I once worked on an early era "smart" phone whose apps were written in a visual basic-like clone. We were silicon valley cool kids and thought people would love too write apps in a high level language rather than C or C++. This was pre-web, pre-javascript, pre-Android, pre-iOS. The large Japanese tech company putting the phone out was staffed by a bunch of electrical engineers whose idea of programming was a table driven state machine, so they used Excel to model the UI for the entire phone as one huge state machine, then wrote Excel basic that took that spreadsheet and generated the proprietary basic code for the device's UI. We thought they'd want to write basic code, but they wanted to code up a spreadsheet instead.

MR4D wrote at 2021-12-01 12:07:59:

You could always embed an excel table into Word or PowerPoint.

/ducks

colejohnson66 wrote at 2021-12-01 12:26:45:

Well, PowerPoint has been shown to be Turing Complete:

https://youtu.be/uNjxe8ShM-8

cube00 wrote at 2021-12-01 07:36:19:

Time to put in a PR for C2 to act as standard error.

cube00 wrote at 2021-12-01 07:31:44:

_"Your scientists were so preoccupied with whether they could, they didn't stop to think if they should."_

BurnGpuBurn wrote at 2021-12-01 10:02:03:

The reference to Jurassic Park* is actually quite on point, given the dinosaur vba is.

*) I remember Jeff Goldblum saying something along those lines, though I imagine the quote could've come from someone else.

kwhitefoot wrote at 2021-12-01 16:02:12:

I think the knee jerk hatred of VBA is really odd. No other language has given more people an opportunity to create the tools they need.

janjones wrote at 2021-12-01 09:17:55:

Motto of many technical posts on Hacker News front page.

punnerud wrote at 2021-12-01 10:46:56:

That is how a lot of innovation start. That can benefit the company many times the combined time of these kinds of “procrastination”.

It is also a way to give employees motivation.

How else do do figure of “what you don’t know that you know”?

keithalewis wrote at 2021-12-01 14:20:20:

This is quite clever, and probably a joke that I'm not getting, but the Excel C SDK lets you call C/C++ from Excel and vice versa. This is one of my bread and butter tools, and I like nice tools, so I wrote a C++ wrapper around the SDK. It also lets you embed C++ objects in Excel:

https://github.com/xlladdins/xll

max_ wrote at 2021-12-01 07:47:16:

The "blog post"[0] is an actual demo. Click "Run as spreadsheet".

This is amazing for learning.

[0]:

https://mrthefakeperson.github.io/Excel-Virtual-Machine/

nickdothutton wrote at 2021-12-01 08:39:11:

The Dwarves dug too greedily and too deep. You know what they awoke in the darkness of Khazad-dûm.

rodikana wrote at 2021-12-01 03:00:00:

Why? Because we can that's why!

unnah wrote at 2021-12-01 11:33:33:

It could be useful if there was a C program you would like to run, but the only tool available was Excel. Maybe strict IT admins had disabled the ability to run anything but Office, and even VBA macros were disabled. Although in that scenario it would be better if the compiler was written in C and could bootstrap itself.

IncRnd wrote at 2021-12-01 03:02:00:

I think we need a compiler written in excel!

im_down_w_otp wrote at 2021-12-01 03:23:10:

Sheets for modules. A column for each function. A row for each line of code. I weirdly would love to see this.

mikaraento wrote at 2021-12-01 09:53:07:

That is pretty much how macros worked in Excel 4.

kitd wrote at 2021-12-01 07:31:29:

I once wrote an x86 assembler in Lotus 123.

exikyut wrote at 2021-12-01 07:32:50:

_[Need for citation intensifies]_

Banana699 wrote at 2021-12-01 18:56:37:

I don't mean to put down OP but isn't it kinda straight forward since assembly is just a 1:1 correspondence with machine instructions? simply pasting the assembly program into a column then looking up each mnemonic in an association table linking each mnemonic with it's machine representation and writing the result into a new column would work. The Labels->Addresses mapping is another lookup but over the program column itself, looking up the row where the label is defined and using that as the offset from the start address of the program. An assembler is just a fancy string processor, Excel is mighty good at string processing.

What I would bet a respectable sum on is that you can't parse/process/interpret even the simplest recursive languages (e.g. arithemtic, Expr ::= Expr + Expr | NUMBER) from pure Excel. Forget expressing the algorithm, there isn't even a suitable data structure to iterate over.

kitd wrote at 2021-12-01 09:57:07:

Apologies, this was over 30 years ago!

IIRC it made extensive use of lookup tables, both building them and being driven by them.

It wasn't a complete implementation, but it proved the theory and scratched an itch.

exikyut wrote at 2021-12-02 11:19:57:

That's really cool :) and makes perfect sense.

I can see what you mean about it scratching an itch. Definitely piqued my interest!

(Varying "citation needed" didn't quite convey genuine curiosity the way I thought it would.)

mcbuilder wrote at 2021-12-01 03:43:46:

Yes, but can it run DOOM?

IncRnd wrote at 2021-12-01 04:12:38:

That's always the question!

Here is a video of a doom-alike in excel, explained by someone with a bird on his head. He's not clippy, but a real person with a bird on his head. [1]

Here is a video displaying a walk-through of the Excel easter egg that showed the Hall of Tortured Souls! [2]

[1]

https://www.youtube.com/watch?v=s105jek4WUI

[2]

https://www.youtube.com/watch?v=WGqD-J_pRvs

fortran77 wrote at 2021-12-01 14:35:31:

The bird moves to his hand halfway through.

IncRnd wrote at 2021-12-01 21:29:44:

Thankfully, the bird's location doesn't affect the graphical rendering power of Excel.

notinty wrote at 2021-12-01 04:57:02:

[fixed]

IncRnd wrote at 2021-12-01 05:24:34:

Thanks!

tonyedgecombe wrote at 2021-12-01 06:57:30:

Excel 95 contained an Easter egg which was a doom like game.

laumars wrote at 2021-12-01 07:32:59:

It was 3D but it wasn’t really Doom like. It reminded me more of Magic Carpet.

There was a Windows 95 screen saver that was Doom like though.

DHowett wrote at 2021-12-01 14:21:52:

Excel 98 had an Easter egg which was like Magic Carpet! If I recall correctly, you fly over a twisted purple and orange landscape while an obelisk emits the credits.

95 had the “Hall of Tortured Souls”—a 2.5D first-person walker—which was more Doomlike.

laumars wrote at 2021-12-02 07:35:08:

Oh yeah. I completely forgot about that one

https://youtu.be/kK0M74E8PS4

Narishma wrote at 2021-12-01 16:21:30:

There was no Excel 98.

mrguyorama wrote at 2021-12-01 20:53:39:

They mean the excel included in Office `97. That's the disk I'm holding in my hand and that's the version I experienced the weird flying easter egg.

DHowett wrote at 2021-12-02 02:10:58:

Whoops! Yes, thanks.

tonyedgecombe wrote at 2021-12-01 17:20:29:

There was on the Mac.

tambourine_man wrote at 2021-12-01 03:24:55:

The compiled Excel file can be executed by triggering iterative calculation (pressing F9 repeatedly)

I know very little Excel, but can’t you create a loop with it?

Jtsummers wrote at 2021-12-01 03:39:08:

Not without dropping into VBA, at least last I looked. The cell dependency graph should form a DAG. If there is a cycle, it will break (Excel will detect this). A common way to produce a "loop" is to create a row for each iteration depending on the one above (which can actually be handy to see convergence and intermediate values). This means there's no way to do something like:

  // initial
  A1 = 0
  A2 = 100 (the limit)
  A3 = =A3+A1 (self referential, 0 initial)
  // somehow
  A1 = 1
  A2 = 100
  A3 = =A3+A1 == 1

If you could refer to previous values it might be possible, but would also force some synchronization into the process that might be problematic. Like you'd need A1 to only update after A3 has had a chance to read it, then the next, then the next.

gizmo686 wrote at 2021-12-01 03:49:00:

Excel supports iterative calculations, which allows you to use circular references. If you enable it, you need to specify a maximum number of iterations excel will run on each update. I believe you can also specify a minimum delta which will cause Excel to terminate early if subsequent iterations differ by less than the delta. I suspect the reason you need to press f9 repeatedly is this project uses circular references, but running your program takes longer than the maximum number of iterations, so pushing f9 allows it to run for another set of iterations.

Jtsummers wrote at 2021-12-01 03:51:22:

That makes sense, I've never made use of that. Apparently that was available as early as Excel 2007, I've just never come across it and haven't used Excel for much more than a scratchpad in years now.

whoknowswhat11 wrote at 2021-12-01 04:14:45:

Goal seek also covers various optimization / iteration scenarios.

Or solver.

Options exist for iterations and maximum change directly with circular references.

https://bettersolutions.com/excel/formulas/circular-referenc...

Adding in indirect/offset/lookups/indexes etc - I've gotten surprisingly far.

I'm also OK doing VBA _BUT_ the MAJOR downside of VBA - horrendous to share it and got worse over time for security reasons.

Excel without VBA - you can give the "program" to anyone, and almost anyone can use it (and in a pinch change it).

RuggedPineapple wrote at 2021-12-01 03:48:20:

This sounds like we're going to learn about macro and VB viruses all over again.

zamadatix wrote at 2021-12-01 03:59:33:

Using newer Excel you also have the power of making custom named functions with LAMBDA() which can also recurse (I think the stack limit is 1024). If you combine this with the idea of columns or rows as iterations of the memory with some of the array functions like MAKEARRAY() and relative position functions like OFFSET() or INDIRECT() you can do pretty much any reasonably sized computation without needing iterative calculation enabled.

The reason being Excel is a tool designed for performing operations on tabular data not designed for general data programming. If you needed programming there was always VBA which was proper so they never wanted to muck it up. LAMBDA made its way in because people wanted reusable function compositions for their tabular data without having to enable the security PITA that is allowing full macros/VBA which can do a lot more than interact with just the data inside the spreadsheet.

pjmlp wrote at 2021-12-01 11:01:06:

Many people stop at VBA, but you can grow beyond it into full VB via .NET Office automation and AddIns, or if feeling miserable, COM in C++.

Additionally if only data transformations are required, there is the F# inspired Power Query.

princeb wrote at 2021-12-01 14:41:34:

vba is fine but it seems to exist halfway outside the calculation chain space that sheets and cells operate in. excel can work with it, but one has to be quite careful with function returns and parameters.

offsets and indirects also exist in that twilight zone being volatile functions.

these three combined can bring down a reasonably sized spreadsheet.

IIAOPSW wrote at 2021-12-01 04:07:58:

Sort of. It is possible to make a loop of mutually dependent formulas. By default this will politely assume you made a mistake and throw a warning message without calculating anything. However, if you know where to poke in the settings, you can enable recursive formulas and use that to rig loops. Ignore the sibling comments answer, VBA is not required.

slaymaker1907 wrote at 2021-12-01 06:43:47:

Excel supports arbitrary recursive functions without macros as of this year. See the new LAMBDA feature with Excel.

keithalewis wrote at 2021-12-01 05:45:24:

This exactly what

https://xllmonte.com

does.

ModernMech wrote at 2021-12-01 04:01:48:

You would accomplish loops in Excel as you would in any array languages (apply operations on columns and tables of data). You can also do recursion in Excel. We used to solve boundary value problems in my computational physics class using Excel.

Extigy wrote at 2021-12-01 08:17:02:

This is disgusting. I love it.

chrishere wrote at 2021-12-01 07:44:28:

There was a time when we used Excel Services in SharePoint to meet some of our business user needs. I wouldn’t use Excel again, but back then it seemed to be a good trade-off between time-to-market and usability (meaning performance for most of the time).

Anyhow, we use

https://github.com/handsontable/hyperformula

to run calculations in our other components these days.

behnamoh wrote at 2021-12-01 03:28:58:

Ironically, 97% of the code is written in F#.

boberoni wrote at 2021-12-01 03:46:26:

Interesting. I wonder the reason for this

This is totally contrived, but I want to believe that this project is a learning project that the creator started to use F# to write a compiler. Perhaps the creator is experienced with imperative programming using C and wanted to do more programming in F#

The reason to do such a thing is that implementing a compiler in a functional programming language results in very elegant functional code. There's an "Aha!" moment when you drop the imperative way of thinking and see how functional thinking can be expressive and concise, yet so very different

I could see myself doing the same thing. It's a seductive intellectual challenge, difficult but achievable, to learn functional programming and write a compiler from scratch

emodendroket wrote at 2021-12-01 03:51:10:

Well, functional languages are often considered a great choice for a compiler, but C is simpler to implement to F#, I'd imagine. The README says it has unfinished F# support too.

cloudhan wrote at 2021-12-01 08:36:04:

Then we need a powerpoint virtual machine[1].

[1]

https://www.andrew.cmu.edu/user/twildenh/PowerPointTM/Paper....

msarrel wrote at 2021-12-01 21:22:23:

It never ceases to amaze me how Wall Street thinks every pipeline needs to flow through Excel. I couldn't believe it 20 years ago and it's even harder to believe today.

SonOfLilit wrote at 2021-12-01 11:02:36:

See also: brainf*k in Google Spreadsheet

https://news.ycombinator.com/item?id=14703098

youaredaniel wrote at 2021-12-01 07:56:23:

cool

cbsmith wrote at 2021-12-01 08:01:22:

The always required: "Your scientists were so preoccupied with whether they could, they didn’t stop to think if they should."