1 kyu

Compiler to Lambda Calculus

Description
Loading description...
Functional Programming
Compilers
Fundamentals
  • Please sign in or sign up to leave a comment.
  • myst-6 Avatar

    just completed this; it was very fun! thank you

  • DemonXworld Avatar

    Easiest KATA EVER

  • morganbarrett Avatar
    • Needs testing for more valid JS variables e.g _bob, id123, $var, hello_world
    • Needs testing for unary op ! withing expressions e.g 5 + !0 + 3 === 9
    • Needs testing for calling anon functions e.g function(x){return x+1;}(420);
    • JohanWiltink Avatar

      name: either a camelCase identifier consisting of letters only, or a single underscore '_' for an undefined value. names are not limited to a single character.

      Not every name that is valid in JS is valid in this kata, as specified in the description. So none of those names you want is valid. Excluding that.

      === is not defined; that'll have to be ==.

      Also, note that 5 + ! 0 + 3 can have any value greater than or equal to 9, because any positive number is truthy. As soon as ! 0 appears in any expression, the only unambiguous continuation is as a Boolean. Nothing should keep you from returning 2 for ! 0 ! ( Or 1, or 1 000. )

    • JohanWiltink Avatar

      Tests added.

      Issue marked resolved by JohanWiltink 3 years ago
  • JohanWiltink Avatar

    add testing for !

  • Kacarott Avatar

    Beautiful kata. Potentially my favourite kata on the site.

    I made the mistake of using the 'standard' encoding of true internally (and forgetting about it), which caused a very difficult bug to find later. A bit more careful planning would have helped a lot :P

    A few things:

    • You don't seem to have any tests for defining constants (besides constants which are functions.)

    • When I removed the DEBUG I got a lot of errors. Ideally that should default to false, if undefined. (Only a minor thing though).

    Thanks for the kata! (Hopefully it gets out of beta one day!)

    • Kacarott Avatar

      Just to clarify the thing about constants, a function like the following might be a good addition:

      function cylinderArea(r) {
        const pi = 3 ;
        return function (h) {
          const circleArea = r ** 2 * pi ;
          return h * circleArea ;
        } ;
      }
      
    • JohanWiltink Avatar

      Oh lovely! An excuse to define pi to 3 ! :P

      You're not supposed to remove DEBUG altogether. I'll look into if I can default it to false, but if you remove it, then wnt it back, how are you going to remember it's there?

      Doing Church true - I empathise, but I see no way to prevent you from being stupid. It's specified adequately, no?

      Oh wait, you solved it! Nice! :D I see lots of regexes. :P

      "Favourite kata" - did you do the BF transpiler? That inspired this, and internally it's even more bonkers than this. But thanks. :] I liked making it, and both ( :P ) of my solvers so far have high praise. Getting it approved, if ever, will only be icing on that cake.

    • Kacarott Avatar

      Yes it is adequately specified, no complaints here. Unluckily though the wrong true still worked far too often, meaning I only realised my mistake when I couldn't pass fib or isPrime.

      I haven't done BF transpiler yet, I'll get there eventually. I am working my way through my bookmarked katas which has built up a lot.

    • JohanWiltink Avatar

      true is tested separately, right after 42! How the He11 did you pass that then?

      const should not be the same as $. JS lack of typechecking?

    • Kacarott Avatar

      How the He11 did you pass that then?

      Because TRUE=a=>b=>a and toInteger=n=>n(x=>x+1)(0), so 'true' came out as x=>x+1, and Boolean(x=>x+1) === true

      (I am not sure what you mean by the const comment)

    • JohanWiltink Avatar

      In Haskell terms, Church true = const. In this kata, true = ($).

      Boolean(inc) should not have been true. Type errors are hard to catch in JS, but with currying, I should at least be able to force a type error by converting the Number to a Church Boolean and aplying that with JS true and false. I think I can change JS Boolean to LC Number ( s => z => true ) (false).

    • Kacarott Avatar

      Ah I see what you mean. Yes I was going to suggest something like that but I thought maybe I am making a big deal about an issue that no one except me will face :P

      Since you are requiring the output to be Int (and floats don't make sense in this context) might a simple typeof x === 'number' be enough? Of course your way is more on theme though.

    • JohanWiltink Avatar

      I have to figure out ( again - even though I wrote it myself ) how testng is done exactly. :]

      I think the root problem indeed is that your solution returned an object instead of a number. false is tested also - but zero and false are equal!

      ( You'll have to wait 'till after the weekend for Lists as Folds II now. You just did that to yourself. :P )

    • JohanWiltink Avatar

      I updated testing. Returning non-numbers for booleans should now throw; removing DEBUG should not throw; I have added your cylinderArea, for which I am massively grateful.

      If you could check if that true bug is caught, I would be even more massively grateful. The second test in the first group should catch it ( and possibly more later on ). I don't know how difficult it is to reintroduce that bug?

      ETA: toBoolean in the example tests should look like const toBoolean = term => { something }. If it's an expression fat arrow thingie, refresh. ( Example tests and Submit tests are almost exactly the same. )

    • JohanWiltink Avatar

      I changed True = One to True = K in my own solution, and I got only two errors! And I failed only one test in the previous version of the tests ..! :O

      Tests may have been optimised for correct solutions a little too much ..

    • Kacarott Avatar

      The true bug seems dealt with (and the error message it presents makes it easy to see what went wrong). I don't know how someone would reintroduce that bug, but it would be an encoding I am unfamiliar with I think.

      The cylinder test looks good! I hope no one gets offended by integer pi :P

    • JohanWiltink Avatar

      I hope someone does! 🙂🙃🙂

      I thought about doing h * r * r * 22 / 7, but I didn't want to change your code; it also meant one less const name = $Number.

  • Kacarott Avatar

    I am curious why multiple return statements, or const after return, etc. should raise an Error? (Since they are valid, if useless, JS?)

    Also, are "pseudo evals" (such as Function("return " + js)()) permitted?

    • JohanWiltink Avatar

      Multiple return statements and const after return can't be expressed in LC as specified here. ( A LC expression has a single return value; it's comparable to a JS fat arrow expression. ) I liked the Error better than silently ignoring code.

      eval, pseudo or not, is fine with me. Your return value must be valid LC, so you can't use eval in there anyway. The only reason eval went away is because I needed a LC parser / evaluator, named it eval because I could, and was too lazy ( and too scared to make mistakes ) to rename it before publishing. ( This kata was months in the making as a kumite. I did not even intend to publish it as a kata until after it was essentially finished. )

      Question marked resolved by JohanWiltink 4 years ago
  • Blind4Basics Avatar

    Hi Johan,

    This is the fastest/simplest way to reach you, so posting here. Could you explain what happened there, plz...? :/

    • JohanWiltink Avatar

      Because they were approvable. If the system is broken, fix the system. Why is everyone raising issues after the fact? Why aren't these kata retired by CodeWars?

      Seriously: what happens these days is someone publishes a kata, it gets downvoted by jaded experienced users ( including me ) a couple of times, it skirts by retirement because someone finds something worth saving, then it starts collecting upvotes from normal users. Then, after a couple of years, it collects enough upvotes to become approvable. I can only conclude this is what CodeWars wants.

      It's also completely unclear who CodeWars is and who is CodeWars. We the users write our own kata, our own documentation, and our own code of conduct. And we the power users revel in the negative, in destroying aspiring kata authors and their work even if it's an honest effort, and in recent years we inflate rankings to something unrecognisable and unreconcilable with one of the few things that's obviously CodeWars ex cathedra, the ranking descriptions by the kyu buttons.

      This is a meta discussion for which this place is not suitable. But I don't do Gitter and that's unfindable for new users anyway, so where are they - and I - to find guidelines that are not just de facto standards, written by the butcher inspecting his own meat ( this is a Dutch saying for which I know no better English translation ) ? Why can't I do what the system allows me to do?

      Sure, some of those kata I approved had problems. But those problems were not bad enough for people not to like those kata, were not bad enough for people to actually raise issues on them, those kata were getting solved and upvoted anyway, by real, normal users. They like them. The decent thing to do seemed to be approving them, so they can find even more of an audience.

      The system allows that, so, again, I can only conclude that is what the system wants.

      If the system is broken, fix the system.

      If some kata need to be retired, they need to be retired.

    • FArekkusu Avatar

      > The system is broken > So I'm gonna abuse this fact

      If you keep ignoring all the issues all the time, and justify it with some bullshit like "but the system allows me to do it" or "this kata is old == we shouldn't fix it", you'll only end up reported for griefing.

    • JohanWiltink Avatar

      Being reported to CodeWars would at least mean I know who to defer to.

      "Reporting me" to self-policing users won't do much good, will it? Or are "you" just going to bully away anyone "you" don't like ?

    • Blind4Basics Avatar

      Johan, I hear you (despite what you maybe think).

      But, hear me too, plz.


      You're stretching your views/acts in two completely different directions. For example:

      But those problems were not bad enough for people not to like those kata, were not bad enough for people to actually raise issues on them

      while you perfectly know that:

      1. most users don't review katas
      2. most of the kata you approved were very old ones (most are from 2016), so not that much of fresh completions from users who possibly would pay attention to the tests because years ago, nobody was reviewing anything like these days.
      3. A kata that is approvable may still have flaws. That's the resposibilty of the approver to check that. He may overlook some things from time to time, that's not a problem. Other users can go by to find what he missed. But when the approver obviously didn't make any effort to look at what the test do or what might be missing from the description and so on, that's a problem.

      Why can't I do what the system allows me to do?

      The system allows you to fix katas before approval too (or even after). So why don't you do that first? Why allow low quality kata to go out of beta while some updates here and there can make them qualitative enough?

      Just 3 examples:

      • the restaurant and Achille number kata were a good base already. Lots of flaws in the second. It took me a non negligible amount of time to fix all of this, yeah... But now they are in shape (or the closest they can be without me losing my sanity... x) ).
      • the Insane TA one is still in very bad shape. See my message for an explanation. So for now, it'd be good for retirement, yes. But even with that base, it can be changed to something correct/interesting. But that needs work.

      When reviewing a beta, if it has flaw but you want to approve it because you think it has potential, just modify the kata before you approve it. I don't count anymore the number of kata I fixed myself before I approved them. I don't count either those I had to rewrite almost from scratch, because they were beyond repair, while being of real interest. So, see, that's possible. But that takes time, yeah.

      I'm also perfectly fine with the fact that, maybe, you're not up to spend hours on a beta to correct/upgrade it. But in that case, don't approve something that has evident flaws. I honestly find the behavior disrespectful for those who try to actually improve the overall quality of the database.

      Raise an issue explaining what the problems are. Possibly suggest solutions. The old betas are alredy safe from retirement so raising issues allow to keep the low quality stuff unapproved, while it's still there: maybe some motivated user will go by and fix what's needed.
      Or maybe not.

      But when you approve a kata like this (ie. with flaws), you're forcing the hand of those who care to actually do what you, as approver, were supposed to do. Does that sound like a reasonnable/sympathetic behaviour to you? :o To me it doesn't, I'm sorry.


      Now considere the other side of the problem:

      Why are there so many kata with a lot of issues?

      • because the authors aren't there anymore
      • because some aren't competent in this or that language and the translator isn't there
      • because a lot of people just don't care about fiwing the problems they caused...

      And now, what is an approved kata? A kata which is, well... approved by the community. Bad things were done years ago, yeah, and we have awful stuff approved. But why contnue on this side? This is just encouraging authors to go in the wrong direction.

      If a structural problem lays there (and it does for sure), there is no need to amplify it even further, don't you think? (talking about approving without fixing, here).


      The system allows that, so, again, I can only conclude that is what the system wants.

      Again, you're stretching your judgment in the direction that suits yourself at point x while you go the other way at point y. In a way I personnally find a bit dishonest (the word is too strong, but I don't have anything else on hand, sorry).
      You know the system is broken, so just don't use "just because I can" as a justification. That's only extending the flaw without bringing any positive counterpart.
      It's like ZED or mrtp0 who vote 8 kyu on everything "just because they can". It's really "the system is flawed, let's break it further".


      If the system is broken, fix the system.

      ...but don't abuse it in the meantime. ;)

      If some kata need to be retired, they need to be retired.

      Just gimme the rights, and I'll do some cleaning... ;p (and not only in the betas...)

      Cheers

    • Blind4Basics Avatar

      two messages in the meantime...

      Being reported to CodeWars would at least mean I know who to defer to.

      well, as a matter of fact, cw has now a "mod" team. Hence people who interact directly with kazk. So you know were to go, now (seek for the shields).

    • JohanWiltink Avatar

      What's a mod, and where do I find that? How am I to know?

      Who's kazk, and why is he special? Is he the new Jake? How am I to know? ( Who was Jake anyway? )

      Really, AFAIK, you're just another user. I had noticed that shield, but I have no idea what it is or what it does.

      An awful lot of assumptions are being made. No, I don't know where to go!

    • Blind4Basics Avatar

      Yeah, again, CW is full of flaws about that (comunication and all). But plz, just be a bit helpful, not hidding behind those.

      For a more precise "where", you get choices. All suboptimal, yeah, but still:

      • posting on any kata authored by "a shield"
      • on gitter to contact the same group
      • on the github repo

      cheers

    • JohanWiltink Avatar

      I have actually tried emailing info@codewars.com once. No reply, no action that I could see.

      What I see is a site that has been created once and left to morph into whatever the ( well, some ) users wanted it to be. No action against obvious abuse of the ranking or rating system. No cleaning up of duplicates. No cleaning up of old, decrepit, inadequate beta kata ( or approved ones ).

      I have no idea where new versions of languages come from. There is no meta information anywhere that I can find. I've never understood GitHub, I can look at sources only if I happen across a link. JS Test.assertDeepEquals appeared one day - no documentation, no press release.

      I have almost nothing to go on beyond what the system allows me to do.

    • JohanWiltink Avatar

      What is that shield? What is a mod?

      Also, WTF is zulip?

    • JohanWiltink Avatar

      At least I'm getting answers. :]

      Took approving a couple of shit kata :P but I'm getting answers.

      Can I suggest a page with that information somewhere findable for users ? Please?

      This site is badly in need of some oversight, and users need to know to whom to turn to get something done.

      ETA: Damn, that last sentence is unreadable. Users need to know who's going to actually do that oversight and how to get in touch with those people.

    • Blind4Basics Avatar

      Well, you probably noticed, things are being worked on but are still in very early phase, and not ready yet to be official. That's why I do not feel in position to go further on the topic, especially when the goal of your message feels like it is to point out the lack of officiality of this. But I will try and get attention of someone who knows answers to your questions.

      PS: forget zulip for the very same reasons, for now... ;)

      edit: crossed messages

    • JohanWiltink Avatar

      Well, you probably noticed, things are being worked on but are still in very early phase, and not ready yet to be official.

      It's been that way for my entire time here, I have never seen any real change, things haven't gotten better, and they have gotten worse in several ways. I really hope some improvements are made and some maintenance is done. Will you in the meantime forgive me for believing it when I see it?

      I appreciate your efforts.

    • Blind4Basics Avatar

      Will you in the meantime forgive me for believing it when I see it?

      Sure, Thomas. ;)

    • Unnamed Avatar

      Also, I'd like to note that a link to the CW Wiki has been in the menu for several years and links to GitHub issues have been in Bug Reports and Feature Requests sections of the "forum", IIRC, for even longer.

    • JohanWiltink Avatar

      The Wiki has helpful technical information. But as far as I can tell it's user-generated, no official CW stances there, and no way to ask questions. It's also incomplete. ( Please point me to the section on crowns and shields. )

      The Bug Reports Forum has "File an issue on Github" in large friendly letters. Well, large letters. (1) That scares me away immediately because I don't know GitHub, and (2) that seems to be the place for bug reports, not problems with site use and abuse, copycats, abusive users, lack of maintenance on kata ( see above ) or other "soft" or "fuzzy" issues.

      If I see a user submitting a copied, cheating or otherwise reportable solution, where do I report that? If I experience outright abuse from another user, where do I report that? In both cases: will something actually be done? Who actually runs this show? Who bans users? I have never experienced anyone clearly having or wielding authority; it's all community policing. And if someone won't let himself be policed, any problem is just not going away.

    • Blind4Basics Avatar

      the repo is so far used for any kind of issue.

      examples:

      Shields and crowns have been existing for less than a bunch of days, so don't expect the documentation to be already up to date about that x)

    • hobovsky Avatar

      I will try to answer some of your questions, but please keep in mind that nothing of it has been finally decided, everything is still under evaluation, and things can change, or even be dismissed if they prove to not work. As you can probably see, everything is in very early stage and not much is complete and finally decided, let alone ready for official announcement. But it is an attempt at making things better. Issues you mentioned (and not only these) are fully acknowledged by maintainers, and it's also fully acknowledged that all problems were neglected for the long time. It's not that it helps anything, but there's honest effort to fix things. It was very difficult until now, because, as said, problems were neglected for a long time, and when they got finally acknowledged, technical debt of the site itself was getting in a way. Now it's more or less sorted out, and maintainers can work on further improvements.

      The Wiki has helpful technical information. But as far as I can tell it's user-generated, no official CW stances there, and no way to ask questions. It's also incomplete. ( Please point me to the section on crowns and shields. )

      This is true. Documentation is being improved here. You can see how it's forming here. Not much is ready, many things are just stubs. but it's growing. Many of it is volountary work, and it's done by community. Docs repo is public, so if you would like to contribute in any way: writing, giving ideas, reviewing texts, it would be not only very helpful, but also could get you familiar with Github a bit ;) Things won't improve here if noone contributes.

      The Bug Reports Forum has "File an issue on Github" in large friendly letters. Well, large letters. (1) That scares me away immediately because I don't know GitHub, and (2) that seems to be the place for bug reports, not problems with site use and abuse, copycats, abusive users, lack of maintenance on kata ( see above ) or other "soft" or "fuzzy" issues.

      This is not really like that. Github issue trackers are suitable for tracking various types of issues, not only bugs. Codewars issue tracker collects bugs, feature requests, suggestions, community stuff like abuse reports. It's being maintained and issues are handled.

      If I see a user submitting a copied, cheating or otherwise reportable solution, where do I report that?

      Here. It's been working this way since, like, long time ago.

      If I experience outright abuse from another user, where do I report that?

      Here.

      In both cases: will something actually be done?

      Yes. No. It depends. There are issues which are handled right away (community abuse of varius kinds). There are issues which take some time to verify, process, and finalize, but they are handled (cheaters, excessive copycats which abuse the system on a large scale, and griefers). There are types of issues which were not decided yet how to handle them correctly (copycats on smaller scale).

      Who actually runs this show? Who bans users? I have never experienced anyone clearly having or wielding authority; it's all community policing. And if someone won't let himself be policed, any problem is just not going away.

      This part I get only partially. I agree that it's not written down anywhere, and it's not documented. But I do not see how it would help if it were. First of all, it's a very common knowledge for people who talk each to another. I have impression (please do not take it personally, it's just my impression and I can be completely wrong about it) that you've somewhat choosen to live out of community. You don't like Github, maybe you do not like Gitter, so it's simply very difficult for the information to reach you. You even said (if I get you correctly), that you won't work with tool you don't like even if it could help with your problem. That's OK, it's totally up to you, but I would have a very honest question: how would you want the announcements, information, and knowledge to reach you? What do you consider a proper way of passing information to you?

      Everyone is up to discussion, community is being heard and listened to. Things go slowly, and they're not ready yet. But they go forward. I hope that all these efforts will be successful, because it would be very helpful to the site.

    • JohanWiltink Avatar

      Thanks Blind. Funny to see Alex won't even mention my name.

      And thanks Hobovsky. It's good to hear things are being done. You acknowledge things were not being done for the longest time, and that's where I'm coming from. Hence "I'll believe it when I see it."

      I have missed for over four years where support was, after all, available. I don't do Gitter and I don't know what to do with Github ( it's not that I don't like it, I just don't understand it ). No, I'm not part of the community outside of codewars.com proper. So everyone there knowing things didn't help me very much. :P

      So I didn't know who's who, who to listen to, who to talk to. I have wondered more than once over the past years if there was someone with real authority, and I have been unable to find anyone. There was a Jake once, and later there was Kazk, but he seemed overwhelmed with technical issues. That made for total anarchy where nobody had to listen to anything anyone said, because there's community policing only, and sometimes that just did not seem to be enough when tempers flared. Meanwhile, ranking standards went down the drain and kata duplication only ever got worse, never better. There must have been some moderating of comments and banning of users going on, but never so apparent to me that I wasn't disheartened by the general slide down the drain I saw happening.

      Anyway. I missed that Forum -> Bug Reports -> "non-content related issue" includes "I have some problem with another user ( or vice versa )". And it never occurred to me to click on Issues in the Wiki - I thought that had to do with bugs in the website or langage / testing framework or something. You know, technical stuff. "Support" should maybe not be labeled "Issues" or "Bug Reports" ( talking about the Forum entry here ). And if you make it to that list, could "spammers" and "cheaters" be pinned to the top? "duplicate kata" is not an Issue, I found, but a Wiki page.

      ETA: For important news, like new versions of languages or important changes to testing frameworks ( if that ever happens without a new langauge version ), a notification pointing to an article of documentation somewhere. ( I hope that kind of new stuff gets documented reasonably fast. ) Possibly only if the applicable language is one of My langauges. Introduction of crowns and shields: write it up in the Wiki and send a notification.

    • JohanWiltink Avatar

      Blind ( or anyone else reading ),

      is there an ongoing Issue for kata that really, really should be reranked? I could not find one.

      Bob's Jump has performance requirements that necessitate memoisation or DP, and it's ranked 7. That's just outrageous IMO. Or is it worth opening a standalone issue for this?

    • hobovsky Avatar

      There was this: https://github.com/codewars/codewars.com/issues/2001 and this: https://github.com/codewars/codewars.com/issues/2030 backed by corresponding lists on wiki, but these were related to some specific instances of the problem.

      You can open more general issue, and create list on wiki, but the problem is already recognized as a kind of Pandora's box with no really good solution. It's been complained on, and discussed, unfortunately without any good consensus. If you have any idea, you can search for any post or issue related to idiotic difficulty rankings and post it there.

    • hobovsky Avatar

      I am not sure if it's worth opening specific issue dedicated for this kata, but I can ask. I Will ask What would be the best way to handle it and open the github issue if necessary.

    • ejini战神 Avatar

      Okay managed to stumble upon this post....

      It's been that way for my entire time here, I have never seen any real change, things haven't gotten better, and they have gotten worse in several ways. I really hope some improvements are made and some maintenance is done.

      Yes, it's been done in 15 months only (not even 20% time of CW's life span!!!)

      The Wiki has helpful technical information. But as far as I can tell it's user-generated, no official CW stances there

      Now we have CW official docs in good shape though still expanding in other languages' documentation part

      and no way to ask questions

      We now have discord, and you're actually in it in which once you were very reluctant to get involved XD

      If I see a user submitting a copied, cheating or otherwise reportable solution, where do I report that? If I experience outright abuse from another user, where do I report that? In both cases: will something actually be done? Who actually runs this show? Who bans users?

      Mods have ability to do that, so not to worry ! Just file a github report on the corresponding issue linked above ~~

      ETA: For important news, like new versions of languages or important changes to testing frameworks ( if that ever happens without a new langauge version )

      Discord is now the main news broadcasting channel !

      is there an ongoing Issue for kata that really, really should be reranked? I could not find one.

      All noted here and still ongoing

      Bob's Jump has performance requirements that necessitate memoisation or DP, and it's ranked 7. That's just outrageous IMO. Or is it worth opening a standalone issue for this?

      You can always brought the issue to discord #fixing channel or raise it on content-issue section to be addressed soon!

      So all in all , after 15 months only:

      • CW mods have proven to be successful
      • Mods can revert betas back to drafts
      • Unpublishing duplicates katas are possible now
      • Mods have power to catch cheaters
      • Language version updates are done more proactively
      • More users are involved in improving community standards
      • Old betas are salvaged and many of them were fixed & approved ~~
      • Kata fixes and language / translation updates are done more systematically
      • Lots of CW bugs are fixed
      • and many more...........

      So, everything is going in the right track ! Hopefully for upcoming years as well, kudos !!! 😜