The Imperium Programming Language - IPL

joeyd999

Joined Jun 6, 2011
5,237
I'm not looking for anything, you asked if C could provide nanosecond delays like a NOP does in assembler, I then reasoned that you'd find it helpful if it did.

You were asking for a way for a language to give you nanosecond delays, we were talking about programming languages.

Finally please do not speculate that "they all look the same to you", your opinion of how things look to me has no place here, we were discussing programming languages.
Now you're just making things up. I was asking for a way to construct macros in C the way I do then in .asm and used NOP() as a minor example.

I'm done. Next subject.
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
As for stifling, here's a nice little challenge for the C devotees here. Its called the sum of digits. That is given a sequence of decimal digits, continually add the digits until there is only one digit left.

e.g.

  • 165 => 1+6+5 => 12 => 1+2 => 3
  • 8036 => 8+0+3+6 => 17 => 8

There is no defined bound to the length of the initial sequence and it cannot be empty and will contain only the digits 0 thru 9.

Write me some C code to do this - that's the challenge, if we pass 8036 we get 8, if we pass 165 we get 3, use any data types you like.
Any takers?
 

xox

Joined Sep 8, 2017
838
Any takers?
Sure!

Code:
#include <ctype.h>
#include <stdlib.h>

size_t sum_of_digits(size_t value) {
  size_t sum = 0;
  for (;;) {
    sum += value % 10;
    value /= 10;
    if (value == 0) {
      if (sum < 10)
        return sum;
      value = sum;
      sum = 0;
    }
  }
}

enum { sum_of_digits_invalid = -1 };

size_t sum_of_digits_in_text(const char* text) {
  size_t sum = 0;
  for (;;) {
    int ch = *text++;
    if (ch == 0)
      break;
    if (!isdigit(ch))
      return sum_of_digits_invalid;
    sum += ch - '0';
  }
  return sum_of_digits(sum);
}

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char** argv) {
  puts("[Sum of Digits Calculator]");
  if (argc == 1) {
    fprintf(stderr, "Usage: %s [...VALUES...]\n", argv[0]);
    srand(time(NULL));
    size_t value = rand();
    printf("%zu: %zu\n", value, sum_of_digits(value));
  }
  else for (;;) {
    char* input = *(++argv);
    if (input == NULL)
      break;
    size_t result = sum_of_digits_in_text(input);
    if (result == sum_of_digits_invalid)
      fprintf(stderr, "ERROR: invalid natural number `%s`\n", input);
    else
      printf("%s: %zu\n", input, result);
  }
}
 

joeyd999

Joined Jun 6, 2011
5,237
C:
int sod(int n)
{
   int m;
   return ((m=(n)?n%10+sod(n/10):0)>9)?sod(m):m;
}
It looks more mysterious this way:

C:
int sod(int n)
{
   int m;
   return ((m=(n)?n%10+sod(n/10):n)>9)?sod(m):m;
}
 
Last edited:

xox

Joined Sep 8, 2017
838
C:
int sod(int n)
{
   int m;
   return ((m=(n)?n%10+sod(n/10):0)>9)?sod(m):m;
}
You've got an off-by-one bug there. Should be:

Code:
int sod(int n)
{
   int m;
   return ((m=(n)?n%10+sod(n/10):0)>=10)?sod(m):m;
}
Oh hey, I just ran my program on the number 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244524442443244224412440243924382437243624352434243324322431243024292428242724262425242424232422242124202419241824172416241524142413241224112410240924082407240624052404240324022401240023992398239723962395239423932392239123902389238823872386238523842383238223812380237923782377237623752374237323722371237023692368236723662365236423632362236123602359235823572356235523542353235223512350234923482347234623452344234323422341234023392338233723362335233423332332233123302329232823272326232523242323232223212320231923182317231623152314231323122311231023092308230723062305230423032302230123002299229822972296229522942293229222912290228922882287228622852284228322822281228022792278227722762275227422732272227122702269226822672266226522642263226222612260225922582257225622552254225322522251225022492248224722462245224422432242224122402239223822372236223522342233223222312230222922282227222622252224222322222221222022192218221722162215221422132212221122102209220822072206220522042203220222012200219921982197219621952194219321922191219021892188218721862185218421832182218121802179217821772176217521742173217221712170216921682167216621652164216321622161216021592158215721562155215421532152215121502149214821472146214521442143214221412140213921382137213621352134213321322131213021292128212721262125212421232122212121202119211821172116211521142113211221112110210921082107210621052104210321022101210020992098209720962095209420932092209120902089208820872086208520842083208220812080207920782077207620752074207320722071207020692068206720662065206420632062206120602059205820572056205520542053205220512050204920482047204620452044204320422041204020392038203720362035203420332032203120302029202820272026202520242023202220212020201920182017201620152014201320122011201020092008200720062005200420032002200120001999199819971996199519941993199219911990198919881987198619851984198319821981198019791978197719761975197419731972197119701969196819671966196519641963196219611960195919581957195619551954195319521951195019491948194719461945194419431942194119401939193819371936193519341933193219311930192919281927192619251924192319221921192019191918191719161915191419131912191119101909190819071906190519041903190219011900189918981897189618951894189318921891189018891888188718861885188418831882188118801879187818771876187518741873187218711870186918681867186618651864186318621861186018591858185718561855185418531852185118501849184818471846184518441843184218411840183918381837183618351834183318321831183018291828182718261825182418231822182118201819181818171816181518141813181218111810180918081807180618051804180318021801180017991798179717961795179417931792179117901789178817871786178517841783178217811780177917781777177617751774177317721771177017691768176717661765176417631762176117601759175817571756175517541753175217511750174917481747174617451744174317421741174017391738173717361735173417331732173117301729172817271726172517241723172217211720171917181717171617151714171317121711171017091708170717061705170417031702170117001699169816971696169516941693169216911690168916881687168616851684168316821681168016791678167716761675167416731672167116701669166816671666166516641663166216611660165916581657165616551654165316521651165016491648164716461645164416431642164116401639163816371636163516341633163216311630162916281627162616251624162316221621162016191618161716161615161416131612161116101609160816071606160516041603160216011600159915981597159615951594159315921591159015891588158715861585158415831582158115801579157815771576157515741573157215711570156915681567156615651564156315621561156015591558155715561555155415531552155115501549154815471546154515441543154215411540153915381537153615351534153315321531153015291528152715261525152415231522152115201519151815171516151515141513151215111510150915081507150615051504150315021501150014991498149714961495149414931492149114901489148814871486148514841483148214811480147914781477147614751474147314721471147014691468146714661465146414631462146114601459145814571456145514541453145214511450144914481447144614451444144314421441144014391438143714361435143414331432143114301429142814271426142514241423142214211420141914181417141614151414141314121411141014091408140714061405140414031402140114001399139813971396139513941393139213911390138913881387138613851384138313821381138013791378137713761375137413731372137113701369136813671366136513641363136213611360135913581357135613551354135313521351135013491348134713461345134413431342134113401339133813371336133513341333133213311330132913281327132613251324132313221321132013191318131713161315131413131312131113101309130813071306130513041303130213011300129912981297129612951294129312921291129012891288128712861285128412831282128112801279127812771276127512741273127212711270126912681267126612651264126312621261126012591258125712561255125412531252125112501249124812471246124512441243124212411240123912381237123612351234123312321231123012291228122712261225122412231222122112201219121812171216121512141213121212111210120912081207120612051204120312021201120011991198119711961195119411931192119111901189118811871186118511841183118211811180117911781177117611751174117311721171117011691168116711661165116411631162116111601159115811571156115511541153115211511150114911481147114611451144114311421141114011391138113711361135113411331132113111301129112811271126112511241123112211211120111911181117111611151114111311121111111011091108110711061105110411031102110111001099109810971096109510941093109210911090108910881087108610851084108310821081108010791078107710761075107410731072107110701069106810671066106510641063106210611060105910581057105610551054105310521051105010491048104710461045104410431042104110401039103810371036103510341033103210311030102910281027102610251024102310221021102010191018101710161015101410131012101110101009100810071006100510041003100210011000999998997996995994993992991990989988987986985984983982981980979978977976975974973972971970969968967966965964963962961960959958957956955954953952951950949948947946945944943942941940939938937936935934933932931930929928927926925924923922921920919918917916915914913912911910909908907906905904903902901900899898897896895894893892891890889888887886885884883882881880879878877876875874873872871870869868867866865864863862861860859858857856855854853852851850849848847846845844843842841840839838837836835834833832831830829828827826825824823822821820819818817816815814813812811810809808807806805804803802801800799798797796795794793792791790789788787786785784783782781780779778777776775774773772771770769768767766765764763762761760759758757756755754753752751750749748747746745744743742741740739738737736735734733732731730729728727726725724723722721720719718717716715714713712711710709708707706705704703702701700699698697696695694693692691690689688687686685684683682681680679678677676675674673672671670669668667666665664663662661660659658657656655654653652651650649648647646645644643642641640639638637636635634633632631630629628627626625624623622621620619618617616615614613612611610609608607606605604603602601600599598597596595594593592591590589588587586585584583582581580579578577576575574573572571570569568567566565564563562561560559558557556555554553552551550549548547546545544543542541540539538537536535534533532531530529528527526525524523522521520519518517516515514513512511510509508507506505504503502501500499498497496495494493492491490489488487486485484483482481480479478477476475474473472471470469468467466465464463462461460459458457456455454453452451450449448447446445444443442441440439438437436435434433432431430429428427426425424423422421420419418417416415414413412411410409408407406405404403402401400399398397396395394393392391390389388387386385384383382381380379378377376375374373372371370369368367366365364363362361360359358357356355354353352351350349348347346345344343342341340339338337336335334333332331330329328327326325324323322321320319318317316315314313312311310309308307306305304303302301300299298297296295294293292291290289288287286285284283282281280279278277276275274273272271270269268267266265264263262261260259258257256255254253252251250249248247246245244243242241240239238237236235234233232231230229228227226225224223222221220219218217216215214213212211210209208207206205204203202201200199198197196195194193192191190189188187186185184183182181180179178177176175174173172171170169168167166165164163162161160159158157156155154153152151150149148147146145144143142141140139138137136135134133132131130129128127126125124123122121120119118117116115114113112111110109108107106105104103102101100999897969594939291908988878685848382818079787776757473727170696867666564636261605958575655545352515049484746454443424140393837363534333231302928272625242322212019181716151413121110987654321

Looks like the sum is 4!
 

joeyd999

Joined Jun 6, 2011
5,237
I actually spent some time trying to eliminate the intermediate int m. I think there is a way to do it, but the solution is evading me.
 

nsaspook

Joined Aug 27, 2009
13,086
Sort of strange this thread has diverted from Idealized hardware programming once most of those Idealized hardware ideas were shown to be questionable.
 

WBahn

Joined Mar 31, 2012
29,979
As for stifling, here's a nice little challenge for the C devotees here. Its called the sum of digits. That is given a sequence of decimal digits, continually add the digits until there is only one digit left.

e.g.

  • 165 => 1+6+5 => 12 => 1+2 => 3
  • 8036 => 8+0+3+6 => 17 => 8

There is no defined bound to the length of the initial sequence and it cannot be empty and will contain only the digits 0 thru 9.

Write me some C code to do this - that's the challenge, if we pass 8036 we get 8, if we pass 165 we get 3, use any data types you like.
You haven't defined the problem completely. When you say "a sequence of decimal digits", what does that mean? Is this an string of ASCII codes with each character representing one of the decimal digits? Is it an unsigned integer and the sequence of digits is implied as being the digits that would be printed if it were displayed as a base-10 value?

Let's take the first one.

Code:
#include <stdio.h>

int main(void)
{
    char seq[] = "1234567890987654321";
    char *p;
    int total;
    
    for (p = seq, total = 0; *p; p++)
        total += *p - ((*p > '9'-total)? '9' : '0');
    
    printf("Sum of digits [%s] = %i\n", seq, total);
    
    return 0;
}
Let's take the second one.

Code:
int main(void)
{
    unsigned long long int seq = 1234567890987654321;
    int total = 0;
    
    printf("Sum of digits [%llu] = ", seq);
    while (seq > 0)
    {
        total -= ((total += seq%10) > 9)? 9 : 0; 
        seq /= 10;
    }
    printf("%i\n", total);
    
    return 0;
}
 

Ya’akov

Joined Jan 27, 2019
9,079
This is off-topic, so I will keep it very brief. @ApacheKid, do you know about PWAs? I know that you are using .NET and so Blazor is particularly useful, but PWAs are “free” and not-quite-but-soon-to-be universal when Apple gets its act together. (Apple effectively invented PWAs as the original idea for apps on the iPhone, but the idea didn’t catch on and they just dropped it on the floor).
 

Gorbag

Joined Aug 29, 2020
13
I'm not sure if you are talking about essentially an HDL (to specify the layout of an MCU from commercial chips and/or design of specific ASICs for or programming FPGAs on your MCU), a programming language for arbitrary MCUs (someone else designed, e.g. Beaglebone) or one for an MCU you plan to design yourself?

If the latter, one would typically start with the application, write an ASL (application specific language) for it, break it down into something lower level (assembly, say) and then optimize the selection of components for the expected workload, so you'd really be asking about language design issues best served by software experts. If the middle one your question devolves into a language popularity contest, and even amoung hardware engineers you are unlikely to learn anything other that someone else's personal preference. Only the first question is really interesting for hardware engineers, but that doesn't seem to be the focus here!
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
Sort of strange this thread has diverted from Idealized hardware programming once most of those Idealized hardware ideas were shown to be questionable.
All ideas are - or should be - questionable, like the idea that the fifty year old C programming language with its crippled grammar, is the best possible language for programming MCUs in the 21st century.
 
Last edited:

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
I'm not sure if you are talking about essentially an HDL (to specify the layout of an MCU from commercial chips and/or design of specific ASICs for or programming FPGAs on your MCU), a programming language for arbitrary MCUs (someone else designed, e.g. Beaglebone) or one for an MCU you plan to design yourself?

If the latter, one would typically start with the application, write an ASL (application specific language) for it, break it down into something lower level (assembly, say) and then optimize the selection of components for the expected workload, so you'd really be asking about language design issues best served by software experts. If the middle one your question devolves into a language popularity contest, and even amoung hardware engineers you are unlikely to learn anything other that someone else's personal preference. Only the first question is really interesting for hardware engineers, but that doesn't seem to be the focus here!
Well the HDL for FPGA, is extremely interesting. The subject rarely comes up in this forum though, although I've dabbled in FPGAs and studied digital electronics in the early 80s in college, I know very little about the problem domain. However I did notice how Verilog is very C-like (grammatically speaking), which kind of underlines my core thesis, which is that many new languages simply presume the C grammar as their starting point, which is - for a variety of reasons - an innovation stifling step.

Personally speaking I wonder if functional languages might be more useful in FPGA 'programming' than imperative languages.
 

Gorbag

Joined Aug 29, 2020
13
Well the HDL for FPGA, is extremely interesting. The subject rarely comes up in this forum though, although I've dabbled in FPGAs and studied digital electronics in the early 80s in college, I know very little about the problem domain. However I did notice how Verilog is very C-like (grammatically speaking), which kind of underlines my core thesis, which is that many new languages simply presume the C grammar as their starting point, which is - for a variety of reasons - an innovation stifling step.

Personally speaking I wonder if functional languages might be more useful in FPGA 'programming' than imperative languages.
Interestingly enough, I have a personal project I've been working on that will use a declarative language -> VHDL. Though I'm really creating an ASL declarative language for specifying (a certain kind of) processors rather than trying to be generic. And then I'm using a functional language to compile those declarations into VHDL. It'll still be a while before it gets to the point of being useful for anything other than building certain chips I'm interested in though.:)

But I agree with you, standard imperative languages make it hard(er) to express the inherent concurrency of HDLs.
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
You haven't defined the problem completely. When you say "a sequence of decimal digits", what does that mean? Is this an string of ASCII codes with each character representing one of the decimal digits? Is it an unsigned integer and the sequence of digits is implied as being the digits that would be printed if it were displayed as a base-10 value?

Let's take the first one.

Code:
#include <stdio.h>

int main(void)
{
    char seq[] = "1234567890987654321";
    char *p;
    int total;
  
    for (p = seq, total = 0; *p; p++)
        total += *p - ((*p > '9'-total)? '9' : '0');
  
    printf("Sum of digits [%s] = %i\n", seq, total);
  
    return 0;
}
Let's take the second one.

Code:
int main(void)
{
    unsigned long long int seq = 1234567890987654321;
    int total = 0;
  
    printf("Sum of digits [%llu] = ", seq);
    while (seq > 0)
    {
        total -= ((total += seq%10) > 9)? 9 : 0;
        seq /= 10;
    }
    printf("%i\n", total);
  
    return 0;
}
Sure, the source could be just a sequence of bytes or chars, for example it could be a file with millions of ASCII digits in it, use that as the concrete input type.
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
Sort of strange this thread has diverted from Idealized hardware programming once most of those Idealized hardware ideas were shown to be questionable.
Well the point of the exercise (which you seem reticent to participate in) is to show that what you said earlier:

"we don't think in C or any programming language"
Really isn't true, only one person considered a recursive solution for example.

All the solutions too emphasize arithmetic addition as part of the processing, these are the kinds of things that subliminally influence the solution, the fact that many can only "see" the problem through the lens of C, if you use a single programming language routinely in professional work for long enough, it starts to act a "blinkers" and one can't see the wood for the trees.

It can even reach the point where the language itself becomes the be all and end all of problem solving, any suggestion that there might be other, better ways becomes anathema.

The problem can in fact be reduced to a recursive state machine, no arithmetic addition required, no addition of digits, no arithmetic at all, almost childishly simple. But it is unlikely that most C programmers will find that kind of solution because C does indeed direct how they think about data processing problems.

The examples supplied above use addition, subtraction, division, modulo division...
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
Interestingly enough, I have a personal project I've been working on that will use a declarative language -> VHDL. Though I'm really creating an ASL declarative language for specifying (a certain kind of) processors rather than trying to be generic. And then I'm using a functional language to compile those declarations into VHDL. It'll still be a while before it gets to the point of being useful for anything other than building certain chips I'm interested in though.:)

But I agree with you, standard imperative languages make it hard(er) to express the inherent concurrency of HDLs.
It is an interesting problem domain, I am too far removed from it to really appreciate the kinds of things involved though, but as soon as I started to play with Verilog I said "Ahh, no surprises here, designed to 'look like' C".
 
Top