Article View: comp.lang.c
Article #2073Re: variadic min and max, (any some and none, cat and more)
From: fir
Date: Tue, 01 Dec 2026 22:27
Date: Tue, 01 Dec 2026 22:27
87 lines
5572 bytes
5572 bytes
bartc pisze: > On 01/12/2026 20:25, David Brown wrote: >> On 01/12/2026 18:48, bartc wrote: >>> On 01/12/2026 13:53, David Brown wrote: >>>> On 01/12/2026 13:11, bartc wrote: >>> >>>>> Some more: >>>>> >>>>> v := (100, 0) >>>>> m := rotatematrix(15°, "Z") >>>>> println v * (m * m) # rotate 30 deg ac/w >>> >>>>> I found it was simplest just to build-in whatever is needed (this >>>>> language was used with my 3D graphics app). No imports or libraries >>>>> are needed, and every user had the same abilities out-of-the-box. >>>>> >>>>> >>>> >>>> When you have a domain-specific language, and full control of the >>>> language, then built-ins can be easier. The point of techniques >>>> like this, whether in Python or C++, is that the language and >>>> toolchain only needs to support the technique. Then the individual >>>> users or library vendors can use it for any operations and any >>>> types. If someone wants to make a type that supports 8 x 8 matrices >>>> over complex doubles with a binary exponential operator, and write >>>> "matrix A = B *pow* C;", then they can do that with pretty much >>>> identical code as this. Well, they'd have to write code for the >>>> exponential operator in question, and good luck doing that >>>> efficiently manner while keeping numeric stability. But the >>>> wrapping code to support the syntax is straightforward. >>>> >>>> Some other languages, like Haskell, make it easier to write your own >>>> operators and also let you use symbols for them. C++ lets you write >>>> "rotatematrix(15_deg, "Z")", but not "15°". (You'd have to find a >>>> Unicode letter that looks like a degree symbol.) >>> >>> I had the option to use either ° or 'deg': >> >> When you are making the language, you make the rules :-) >> >>> >>> 15 deg >>> >>> There were a number of such suffixes, which acted as scale factors >>> when they followed a constant number. Mostly they were used for >>> lengths, such as "m mm ft ins" (these converted the number to a >>> standard unit, and in my app that was millimetres). >>> >> >> Was it just a scaling factor, or did you distinguish types? In C++, >> when you do this sort of thing (called "user-defined literals") you >> generally attach a specific type to it. Thus if you have "auto x = >> 10_m;", "auto y = 5_s;", trying to add x and y (adding a distance to a >> time) would be a compile-time error - but you could divide them to get >> a speed. >> > > It's just a scale factor. The result is a generic FP type. > > I have looked into properly implementing units, where multiplying tgwo > length types for example gives you an area type, and where area + length > is not allowed, but it very quickly gets out of hand and turns into a > can of works. > > In any case it requires a much stricter, and hierarchical, type system, > such as you might find in Ada, and may be possible in C++. > > I mentioned Frink (https://frinklang.org/) which supports thousands of > physical units. That is so comprehensive that I decided it would be > pointless to emulate a tiny fraction of it within my own PL. > > That's fine; my Casio works perfectly will with unitless numbers. So can > a PL! as tu units i just defined 2 constants in my rasterizer const float G=0.0545f; // ziemskie G 9.81 m/s² const float O=0.0002777778f; // 1 obrót/s² one is linear acceleration unit and one angular acceleration unit my ship having acc = 2*G; yaw_acc = 1*O; seem reasoneble (and opponent ships having also some of that) if im wrong some could correct me, as im not sure if im fully right (those values come from he fat tkah 1 linear is 5 cm here (or 5 cm here is 1 there) and 1 second is 60 frames, 1.0 is full turn
Technical Details
Message-ID:
<11enhk0$28vqo$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11bes8b$1gncr$1@dont-email.me> <11ek7b2$j8f6$1@raubtier-asyl.eternal-september.org> <11ekfu0$mq5n$4@dont-email.me> <11ekg71$n5p7$1@raubtier-asyl.eternal-september.org> <11ekgf8$mq5n$8@dont-email.me> <11ekjsp$pmch$2@raubtier-asyl.eternal-september.org> <11ekq4q$snda$1@dont-email.me> <11em45u$1fp0a$1@dont-email.me> <11emdhn$1ko8h$1@dont-email.me> <11emjh1$1ntap$1@dont-email.me> <11en1a0$1vqc1$1@dont-email.me> <11enagh$24n1m$2@dont-email.me> <11end36$26j38$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: variadic min and max, (any some and none, cat and more) Date: Tue, 1 Dec 2026 23:27:10 +0100 Organization: A noiseless patient Spider Lines: 87 Message-ID: <11enhk0$28vqo$1@dont-email.me> References: <11bes8b$1gncr$1@dont-email.me> <11ek7b2$j8f6$1@raubtier-asyl.eternal-september.org> <11ekfu0$mq5n$4@dont-email.me> <11ekg71$n5p7$1@raubtier-asyl.eternal-september.org> <11ekgf8$mq5n$8@dont-email.me> <11ekjsp$pmch$2@raubtier-asyl.eternal-september.org> <11ekq4q$snda$1@dont-email.me> <11em45u$1fp0a$1@dont-email.me> <11emdhn$1ko8h$1@dont-email.me> <11emjh1$1ntap$1@dont-email.me> <11en1a0$1vqc1$1@dont-email.me> <11enagh$24n1m$2@dont-email.me> <11end36$26j38$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 01 Dec 2026 22:27:13 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2391896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19URsXwkC/X8fj2SjFp6aJDsl1+cDpt+tI="; posting-host="7a19f3f1b9c4b11a1d98366ec728cc9c" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:kftRsKpKDH2Pl7svijWUl2Wznfk= sha256:4gemc3L4coaXhkymzhSiLahaoBrAVP5wVO964smcWDg= sha1:m6s49Fg5a1ulrJQVuKmnUeQqDNI= sha256:M3B9zdY3JvZ4suuysT2odJEp7f39lBWMcfiN7NNGKrc= In-Reply-To: <11end36$26j38$1@dont-email.me>